q-koa 12.4.4 → 12.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core/app.js CHANGED
@@ -648,12 +648,16 @@ class APP {
648
648
  beforeCreate: (res, t) => {
649
649
  try {
650
650
  if (folder === 'log') {
651
- this.app[appName].service.log && this.app[appName].service.log.push({
652
- app: this.app[appName],
653
- appName,
654
- message: res.toJSON().message,
655
- url: res.toJSON().url,
656
- })
651
+ if (this.is_dev && !this.app[appName].service.log) {
652
+ console.error('缺少log/service.js,')
653
+ }
654
+ this.app[appName].service.log &&
655
+ this.app[appName].service.log.push({
656
+ app: this.app[appName],
657
+ appName,
658
+ message: res.toJSON().message,
659
+ url: res.toJSON().url,
660
+ })
657
661
  }
658
662
  if (res.toJSON().user_id) {
659
663
  res.createdid = res.toJSON().user_id
@@ -110,9 +110,9 @@ exports.oss_upload = async (ctx) => {
110
110
  let imageData
111
111
  if (ctx.request.files && ctx.request.files.file) {
112
112
  const { file } = ctx.request.files
113
- fileName = `${
114
- String(new Date().getTime()).split('').reverse().join('') + Math.random()
115
- }.${file.name.split('.')[file.name.split('.').length - 1]}`
113
+ fileName = `${String(
114
+ new Date().getYear() + new Date().getMonth() + Math.random()
115
+ )}.${file.name.split('.')[file.name.split('.').length - 1]}`
116
116
  imageData = file.path
117
117
  } else {
118
118
  const { url: imageUrl, filename: imageFileName } = ctx.request.body
@@ -561,6 +561,44 @@ exports.dashboard = async (ctx) => {
561
561
  ctx.SUCCESS(result)
562
562
  }
563
563
 
564
+ exports.showModelCount = async (ctx) => {
565
+ const { app, appName } = getAppByCtx(ctx)
566
+ const { is_count = false } = ctx.request.body
567
+ const result = await app.sequelize.showAllSchemas()
568
+ const list = result.map(
569
+ (item) => item[`Tables_in_${app.sequelize.config.database}`]
570
+ )
571
+ let tableList = []
572
+ for (let i = 0; i < list.length; i++) {
573
+ if (!app.model[list[i]]) continue
574
+ const defaultConfigPath = path.resolve(__dirname, `../${list[i]}/config.js`)
575
+ const defaultConfigExist = fs.existsSync(defaultConfigPath)
576
+ const target =
577
+ app.config[list[i]] &&
578
+ Object.keys(app.config[list[i]]).length === 0 &&
579
+ defaultConfigExist
580
+ ? require(defaultConfigPath)
581
+ : app.config[list[i]]
582
+ const count = await app.model[list[i]].count()
583
+ const maxTarget = await app.model[list[i]].findOne({
584
+ order: [['id', 'DESC']],
585
+ attributes: ['id'],
586
+ })
587
+ if (maxTarget) {
588
+ tableList = [
589
+ ...tableList,
590
+ {
591
+ count,
592
+ max_id: maxTarget.id,
593
+ name: target.name,
594
+ model: list[i],
595
+ },
596
+ ]
597
+ }
598
+ }
599
+ return ctx.SUCCESS(tableList.sort((a, b) => b.count - a.count))
600
+ }
601
+
564
602
  exports.showAllModel = async (ctx) => {
565
603
  const { app, appName } = getAppByCtx(ctx)
566
604
  const { is_count = false } = ctx.request.body
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "12.4.4",
3
+ "version": "12.4.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {