q-koa 12.4.5 → 12.4.8

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
package/core/config.js CHANGED
@@ -142,7 +142,7 @@ module.exports = {
142
142
  router.get('/cache/clear', app.controller.cache.clear)
143
143
  router.get('/cache/getAll', app.controller.cache.getAll)
144
144
  }
145
- if (app.model.weixin) {
145
+ if (app.controller.weixin) {
146
146
  router.get('/weixin/h5_login', app.controller.weixin.h5_login)
147
147
  router.get(
148
148
  '/weixin/h5_login_callback',
@@ -6,9 +6,29 @@ const is_dev = process.env.NODE_ENV !== 'production'
6
6
  exports.push = async ({ app, appName = '通知', url, message }) => {
7
7
  const log_push_url = lodash.get(
8
8
  app,
9
- 'appConfig.log_push_url',
9
+ 'appConfig.log.url',
10
10
  'https://api.day.app/ieaRfoE3LiPveGbY5qmUwk'
11
11
  )
12
+
13
+ const log_push_excludes = lodash.get(app, 'appConfig.log.excludes', {
14
+ url: [],
15
+ message: ['账号密码错误', 'read ETIMEDOUT'],
16
+ })
17
+ if (
18
+ url &&
19
+ log_push_excludes.url &&
20
+ log_push_excludes.url.some((i) => i.includes(url))
21
+ ) {
22
+ return
23
+ }
24
+
25
+ if (
26
+ message &&
27
+ log_push_excludes.message &&
28
+ log_push_excludes.message.some((i) => i.includes(message))
29
+ ) {
30
+ return
31
+ }
12
32
  if (log_push_url) {
13
33
  const appConfig = getConfig(app)
14
34
  const { site_name, logo_image, logo_img } = await appConfig.getObject(
@@ -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
@@ -61,7 +61,7 @@ module.exports = class Singleton {
61
61
  if (data.message === '查询无结果') {
62
62
  throw new Error(`找不到【${name}】,可能需要更详细一点(省市区)`)
63
63
  } else {
64
- throw new Error(`${this.key.split('-')[0]}${data.message}`)
64
+ throw new Error(`${this.key.split('-')[0]} ${name} ${data.message}`)
65
65
  }
66
66
  }
67
67
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "12.4.5",
3
+ "version": "12.4.8",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {