q-koa 7.7.3 → 7.7.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.
Files changed (62) hide show
  1. package/core/app.js +24 -16
  2. package/core/file/plugins/administrator/controller.js +1 -1
  3. package/core/file/plugins/administrator/model.js +7 -9
  4. package/core/file/plugins/administrator/validate.js +1 -1
  5. package/core/file/plugins/alipay/controller.js +1 -1
  6. package/core/file/plugins/cloudfunction/model.js +3 -3
  7. package/core/file/plugins/common/controller.js +9 -5
  8. package/core/file/plugins/common/validate.js +14 -13
  9. package/core/file/plugins/douyin/controller.js +1 -7
  10. package/core/file/plugins/douyin/validate.js +17 -19
  11. package/core/file/plugins/douyin_user/model.js +1 -1
  12. package/core/file/plugins/good_sku/controller.js +1 -1
  13. package/core/file/plugins/h5_user/model.js +1 -1
  14. package/core/file/plugins/lang/model.js +3 -3
  15. package/core/file/plugins/language/model.js +5 -6
  16. package/core/file/plugins/log/controller.js +1 -1
  17. package/core/file/plugins/log/model.js +1 -1
  18. package/core/file/plugins/model/controller.js +8 -5
  19. package/core/file/plugins/model/model.js +1 -1
  20. package/core/file/plugins/model/service.js +11 -11
  21. package/core/file/plugins/model/validate.js +10 -13
  22. package/core/file/plugins/model_attributes/model.js +1 -1
  23. package/core/file/plugins/mp_user/model.js +1 -1
  24. package/core/file/plugins/permission/model.js +1 -1
  25. package/core/file/plugins/role/controller.js +1 -1
  26. package/core/file/plugins/role/model.js +1 -1
  27. package/core/file/plugins/role_permission/controller.js +1 -1
  28. package/core/file/plugins/role_permission/model.js +7 -8
  29. package/core/file/plugins/routes/controller.js +1 -1
  30. package/core/file/plugins/routes/model.js +1 -1
  31. package/core/file/plugins/setting/afterExecute.js +1 -1
  32. package/core/file/plugins/setting/controller.js +1 -1
  33. package/core/file/plugins/setting/model.js +1 -1
  34. package/core/file/plugins/setting/validate.js +13 -19
  35. package/core/file/plugins/system/controller.js +5 -8
  36. package/core/file/plugins/system/service.js +1 -1
  37. package/core/file/plugins/system/validate.js +20 -14
  38. package/core/file/plugins/todolist/model.js +1 -1
  39. package/core/file/plugins/toutiao/controller.js +1 -6
  40. package/core/file/plugins/toutiao_user/model.js +1 -1
  41. package/core/file/plugins/user/afterExecute.js +38 -33
  42. package/core/file/plugins/user/controller.js +1 -1
  43. package/core/file/plugins/user/model.js +29 -18
  44. package/core/file/plugins/user/test.js +53 -38
  45. package/core/file/plugins/user/validate.js +7 -8
  46. package/core/file/plugins/video/controller.js +4 -6
  47. package/core/file/plugins/video/validate.js +4 -4
  48. package/core/file/plugins/weixin/controller.js +2 -2
  49. package/core/file/plugins/weixin/service.js +4 -3
  50. package/core/file/plugins/weixin/validate.js +26 -27
  51. package/core/file/services/aliSms.js +29 -28
  52. package/core/file/services/alipay.js +1 -1
  53. package/core/file/services/amap.js +6 -6
  54. package/core/file/services/douyin.js +1 -1
  55. package/core/file/services/express.js +4 -4
  56. package/core/file/services/geo.js +1 -1
  57. package/core/file/services/toutiao.js +3 -3
  58. package/core/file/services/weixin.js +21 -12
  59. package/core/file/services/weixinMP.js +3 -2
  60. package/core/file/utils/index.js +1 -1
  61. package/core/restc/lib/index.js +4 -1
  62. package/package.json +1 -1
package/core/app.js CHANGED
@@ -3,6 +3,7 @@ const Router = require('koa-router')
3
3
  const _ = require('lodash')
4
4
  const path = require('path')
5
5
  const fs = require('fs')
6
+ const fsPromise = require('fs/promises')
6
7
  const Sequelize = require('sequelize')
7
8
  const moment = require('moment')
8
9
  const { EventEmitter } = require('events')
@@ -242,7 +243,7 @@ class APP {
242
243
  // console.log(content);
243
244
  // });
244
245
 
245
- starter.on('loadAll', () => {
246
+ starter.on('loadAll', async () => {
246
247
  const appName = this.config.includes[0]
247
248
  this.server = this.app.listen(this.port, () => {
248
249
  console.log(`server is running at http://localhost:${this.port}`)
@@ -261,7 +262,7 @@ class APP {
261
262
  appName: appName,
262
263
  })
263
264
  } else {
264
- fs.writeFileSync(
265
+ await fsPromise.writeFile(
265
266
  `${rootDirectory}/${APP_DIR}/${appName}/${PLUGINS_DIR}/model/service.js`,
266
267
  ''
267
268
  )
@@ -294,7 +295,7 @@ class APP {
294
295
  }
295
296
 
296
297
  async initApp() {
297
- let dirList = fs.readdirSync(
298
+ let dirList = await fsPromise.readdir(
298
299
  path.resolve(__dirname, `${rootDirectory}/${APP_DIR}`)
299
300
  )
300
301
  dirList = dirList.filter((item) => this.config.includes.includes(item))
@@ -359,7 +360,7 @@ class APP {
359
360
  this.initFile(appName)
360
361
  }
361
362
 
362
- this.initPlugin(appName)
363
+ await this.initPlugin(appName)
363
364
  this.app[appName].event = new EventEmitter()
364
365
 
365
366
  const cacheConfig = _.get(this.app[appName], 'appConfig.cache', {
@@ -372,7 +373,7 @@ class APP {
372
373
  maxAge: cacheConfig.maxAge,
373
374
  })
374
375
 
375
- this.initModel(appName)
376
+ await this.initModel(appName)
376
377
  // const models = Object.keys(this.app[appName].model).join(' / ')
377
378
  if (taskConfig.is_available) {
378
379
  this.initTask(appName)
@@ -421,18 +422,21 @@ class APP {
421
422
  }
422
423
  }
423
424
 
424
- initTask(appName) {
425
+ async initTask(appName) {
425
426
  console.log(chalk.red(`启动任务${appName}`))
426
427
  const taskDir = path.resolve(
427
428
  __dirname,
428
429
  `${rootDirectory}/${APP_DIR}/${appName}/task`
429
430
  )
430
431
  const publicExist = fs.existsSync(taskDir)
431
- if (!publicExist) fs.mkdirSync(taskDir)
432
- fs.readdirSync(taskDir).forEach((folder) => {
432
+ if (!publicExist) await fsPromise.mkdir(taskDir)
433
+ const list = await fsPromise.readdir(taskDir)
434
+ for (let i = 0; i < list.length; i++) {
435
+ const folder = list[i]
433
436
  const isFolder = fs.lstatSync(path.resolve(taskDir, folder)).isDirectory()
434
437
  if (isFolder) {
435
- fs.readdirSync(path.resolve(taskDir, folder)).forEach((filename) => {
438
+ const folderDir = await fsPromise.readdir(path.resolve(taskDir, folder))
439
+ folderDir.forEach((filename) => {
436
440
  if (filename === 'index.js') {
437
441
  const task = require(path.resolve(
438
442
  __dirname,
@@ -447,23 +451,27 @@ class APP {
447
451
  }
448
452
  })
449
453
  }
450
- })
454
+ }
451
455
  }
452
456
 
453
- initPlugin(appName) {
457
+ async initPlugin(appName) {
454
458
  const pluginDir = path.resolve(
455
459
  __dirname,
456
460
  `${rootDirectory}/${APP_DIR}/${appName}/${PLUGINS_DIR}`
457
461
  )
458
462
  const publicExist = fs.existsSync(pluginDir)
459
- if (!publicExist) fs.mkdirSync(pluginDir)
460
-
461
- fs.readdirSync(pluginDir).forEach((folder) => {
463
+ if (!publicExist) await fsPromise.mkdir(pluginDir)
464
+ const pluginDirResult = await fsPromise.readdir(pluginDir)
465
+ for (let i = 0; i < pluginDirResult.length; i++) {
466
+ const folder = pluginDirResult[i]
462
467
  const isFolder = fs
463
468
  .lstatSync(path.resolve(pluginDir, folder))
464
469
  .isDirectory()
465
470
  if (isFolder) {
466
- fs.readdirSync(path.resolve(pluginDir, folder)).forEach((filename) => {
471
+ const folderResult = await fsPromise.readdir(
472
+ path.resolve(pluginDir, folder)
473
+ )
474
+ folderResult.forEach((filename) => {
467
475
  const extname = path.extname(filename)
468
476
  if (extname === '.js') {
469
477
  const n = path.basename(filename, extname)
@@ -658,7 +666,7 @@ class APP {
658
666
  }
659
667
  })
660
668
  }
661
- })
669
+ }
662
670
  }
663
671
 
664
672
  initModel(appName) {
@@ -1,4 +1,4 @@
1
- const { getAppByCtx } = require('multiple-quick-koa')
1
+ const { getAppByCtx } = require('q-koa')
2
2
  const md5 = require('js-md5')
3
3
 
4
4
  const superAdmin = {
@@ -1,5 +1,5 @@
1
- const { Sequelize, Random } = require('multiple-quick-koa');
2
- const md5 = require('js-md5');
1
+ const { Sequelize, Random } = require('q-koa')
2
+ const md5 = require('js-md5')
3
3
 
4
4
  exports.name = {
5
5
  type: Sequelize.STRING,
@@ -9,7 +9,7 @@ exports.name = {
9
9
  defaultValue: '',
10
10
  sortOrder: 1,
11
11
  mock: () => Random.cword(5),
12
- };
12
+ }
13
13
 
14
14
  exports.password = {
15
15
  type: Sequelize.STRING,
@@ -21,7 +21,7 @@ exports.password = {
21
21
  set: function (value) {
22
22
  this.setDataValue('password', md5(value))
23
23
  },
24
- };
24
+ }
25
25
 
26
26
  exports.role_id = {
27
27
  type: Sequelize.MEDIUMINT.UNSIGNED,
@@ -30,8 +30,7 @@ exports.role_id = {
30
30
  is_mock: false,
31
31
  defaultValue: 0,
32
32
  sortOrder: 3,
33
-
34
- };
33
+ }
35
34
 
36
35
  exports.query = {
37
36
  type: Sequelize.JSON,
@@ -40,8 +39,7 @@ exports.query = {
40
39
  is_mock: false,
41
40
  defaultValue: {},
42
41
  sortOrder: 4,
43
- };
44
-
42
+ }
45
43
 
46
44
  exports.post = {
47
45
  type: Sequelize.JSON,
@@ -50,4 +48,4 @@ exports.post = {
50
48
  is_mock: false,
51
49
  defaultValue: {},
52
50
  sortOrder: 5,
53
- };
51
+ }
@@ -1,4 +1,4 @@
1
- const { Validator, getAppByCtx } = require('multiple-quick-koa')
1
+ const { Validator, getAppByCtx } = require('q-koa')
2
2
 
3
3
  exports.login = async (ctx) => {
4
4
  const params = {
@@ -1,6 +1,6 @@
1
1
  const Alipay = require('../../services/alipay')
2
2
 
3
- const { getAppByCtx, getConfig } = require('multiple-quick-koa')
3
+ const { getAppByCtx, getConfig } = require('q-koa')
4
4
  exports.h5_pay = async (ctx) => {
5
5
  const { app, appName } = getAppByCtx(ctx)
6
6
 
@@ -1,15 +1,15 @@
1
- const { Sequelize } = require('multiple-quick-koa');
1
+ const { Sequelize } = require('q-koa')
2
2
 
3
3
  exports.name = {
4
4
  type: Sequelize.STRING,
5
5
  comment: '函数名',
6
6
  allowNull: false,
7
7
  defaultValue: '',
8
- };
8
+ }
9
9
 
10
10
  exports.code_content = {
11
11
  type: Sequelize.TEXT,
12
12
  comment: '执行程序',
13
13
  allowNull: false,
14
14
  defaultValue: '',
15
- };
15
+ }
@@ -1,7 +1,8 @@
1
1
  const fs = require('fs')
2
+ const fsPromise = require('fs/promises')
2
3
  const path = require('path')
3
4
  const crypto = require('crypto')
4
- const { Random, lodash, getAppByCtx, getConfig } = require('multiple-quick-koa')
5
+ const { Random, lodash, getAppByCtx, getConfig } = require('q-koa')
5
6
  const Captchapng = require('captchapng')
6
7
  const qr = require('qr-image')
7
8
  const OSS = require('ali-oss')
@@ -36,7 +37,7 @@ exports.upload = async (ctx) => {
36
37
 
37
38
  const { site_host } = await appConfig.getObject('base')
38
39
 
39
- const reader = fs.readFileSync(file.path)
40
+ const reader = await fsPromise.readFile(file.path)
40
41
 
41
42
  const fsHash = crypto.createHash('md5')
42
43
  fsHash.update(reader)
@@ -66,7 +67,7 @@ exports.upload = async (ctx) => {
66
67
  )
67
68
  if (isExists) return ctx.SUCCESS(responseData)
68
69
 
69
- fs.writeFileSync(targetPath, reader)
70
+ await fsPromise.writeFile(targetPath, reader)
70
71
  return ctx.SUCCESS(responseData)
71
72
  }
72
73
 
@@ -220,7 +221,7 @@ exports.swagger = async (ctx) => {
220
221
  `${process.cwd()}/app/${appName}/plugins`
221
222
  )
222
223
  const apis = []
223
- const pathList = fs.readdirSync(filePath)
224
+ const pathList = await fsPromise.readdir(filePath)
224
225
  for (let i = 0; i < pathList.length; i++) {
225
226
  const folder = pathList[i]
226
227
  const isFolder = fs.lstatSync(path.resolve(filePath, folder)).isDirectory()
@@ -240,7 +241,10 @@ exports.swagger = async (ctx) => {
240
241
  const controllerFilePath = path.resolve(filePath, folder, 'controller.js')
241
242
  const isControllerExist = fs.existsSync(controllerFilePath)
242
243
  if (isControllerExist) {
243
- const controllerFile = fs.readFileSync(controllerFilePath, 'utf-8')
244
+ const controllerFile = await fsPromise.readFile(
245
+ controllerFilePath,
246
+ 'utf-8'
247
+ )
244
248
  const annotations = controllerFile.match(annotationsReg)
245
249
 
246
250
  if (annotations) {
@@ -1,4 +1,4 @@
1
- const { Validator } = require('multiple-quick-koa');
1
+ const { Validator } = require('q-koa')
2
2
 
3
3
  exports.email = async (ctx) => {
4
4
  const params = {
@@ -12,24 +12,25 @@ exports.email = async (ctx) => {
12
12
  required: true,
13
13
  message: '请输入邮件主题',
14
14
  },
15
- };
16
- await new Validator(params).validate(ctx.request.body);
17
- };
15
+ }
16
+ await new Validator(params).validate(ctx.request.body)
17
+ }
18
18
 
19
- exports.sendMessage = async ctx => {
19
+ exports.sendMessage = async (ctx) => {
20
20
  const params = {
21
21
  mobile: {
22
22
  type: 'string',
23
23
  required: true,
24
24
  validator: (rule, value) => {
25
- return /^[1][1,2,3,4,5,7,8,9][0-9]{9}$/.test(value) ? Promise.resolve() : Promise.reject('请输入正确手机号');
26
- }
25
+ return /^[1][1,2,3,4,5,7,8,9][0-9]{9}$/.test(value)
26
+ ? Promise.resolve()
27
+ : Promise.reject('请输入正确手机号')
28
+ },
27
29
  },
28
- };
29
- await new Validator(params).validate(ctx.request.body);
30
+ }
31
+ await new Validator(params).validate(ctx.request.body)
30
32
  }
31
33
 
32
-
33
34
  exports.schedule = async (ctx) => {
34
35
  const params = {
35
36
  to: {
@@ -42,6 +43,6 @@ exports.schedule = async (ctx) => {
42
43
  required: true,
43
44
  message: '请输入邮件主题',
44
45
  },
45
- };
46
- await new Validator(params).validate(ctx.request.body);
47
- };
46
+ }
47
+ await new Validator(params).validate(ctx.request.body)
48
+ }
@@ -1,10 +1,4 @@
1
- const {
2
- getAppByCtx,
3
- getConfig,
4
- lodash,
5
- moment,
6
- getService,
7
- } = require('multiple-quick-koa')
1
+ const { getAppByCtx, getConfig, lodash, moment, getService } = require('q-koa')
8
2
  const util = require('util')
9
3
  const axios = require('axios')
10
4
  const qr = require('qr-image')
@@ -1,40 +1,38 @@
1
- const { Validator } = require('multiple-quick-koa')
1
+ const { Validator } = require('q-koa')
2
2
  /**
3
- *
4
- * 详情 https://www.jianshu.com/p/2105c48b45c7
5
- *
6
- */
7
- exports.hotVideo = async ctx => {
3
+ *
4
+ * 详情 https://www.jianshu.com/p/2105c48b45c7
5
+ *
6
+ */
7
+ exports.hotVideo = async (ctx) => {
8
8
  const params = {
9
9
  word: {
10
10
  type: 'string',
11
11
  required: true,
12
12
  message: '请输入热词',
13
13
  },
14
- };
15
- await new Validator(params).validate(ctx.request.body);
16
- };
14
+ }
15
+ await new Validator(params).validate(ctx.request.body)
16
+ }
17
17
 
18
-
19
- exports.videoList = async ctx => {
18
+ exports.videoList = async (ctx) => {
20
19
  const params = {
21
20
  id: {
22
21
  type: 'number',
23
22
  required: true,
24
23
  message: '请输入id',
25
24
  },
26
- };
27
- await new Validator(params).validate(ctx.request.body);
28
- };
25
+ }
26
+ await new Validator(params).validate(ctx.request.body)
27
+ }
29
28
 
30
- exports.fansData = async ctx => {
29
+ exports.fansData = async (ctx) => {
31
30
  const params = {
32
31
  id: {
33
32
  type: 'number',
34
33
  required: true,
35
34
  message: '请输入id',
36
35
  },
37
- };
38
- await new Validator(params).validate(ctx.request.body);
39
- };
40
-
36
+ }
37
+ await new Validator(params).validate(ctx.request.body)
38
+ }
@@ -1,4 +1,4 @@
1
- const { Sequelize } = require('multiple-quick-koa')
1
+ const { Sequelize } = require('q-koa')
2
2
 
3
3
  exports.openid = {
4
4
  type: Sequelize.STRING,
@@ -1,4 +1,4 @@
1
- const { getAppByCtx, lodash } = require('multiple-quick-koa')
1
+ const { getAppByCtx, lodash } = require('q-koa')
2
2
 
3
3
  exports.update = async (ctx) => {
4
4
  const { app } = getAppByCtx(ctx)
@@ -1,4 +1,4 @@
1
- const { Sequelize, Random } = require('multiple-quick-koa')
1
+ const { Sequelize, Random } = require('q-koa')
2
2
 
3
3
  exports.openid = {
4
4
  type: Sequelize.STRING,
@@ -1,15 +1,15 @@
1
- const { Sequelize } = require('multiple-quick-koa');
1
+ const { Sequelize } = require('q-koa')
2
2
 
3
3
  exports.name = {
4
4
  type: Sequelize.STRING,
5
5
  comment: '名字',
6
6
  allowNull: false,
7
7
  defaultValue: '',
8
- };
8
+ }
9
9
 
10
10
  exports.key = {
11
11
  type: Sequelize.STRING,
12
12
  comment: 'key',
13
13
  allowNull: false,
14
14
  defaultValue: '',
15
- };
15
+ }
@@ -1,4 +1,4 @@
1
- const { Sequelize } = require('multiple-quick-koa');
1
+ const { Sequelize } = require('q-koa')
2
2
 
3
3
  exports.name = {
4
4
  type: Sequelize.STRING,
@@ -13,15 +13,14 @@ exports.name = {
13
13
  msg: '名字不允许为空',
14
14
  },
15
15
  },
16
- };
17
-
16
+ }
18
17
 
19
18
  exports.lang_id = {
20
19
  type: Sequelize.INTEGER(11),
21
20
  comment: '语言',
22
21
  allowNull: false,
23
22
  defaultValue: 1,
24
- };
23
+ }
25
24
 
26
25
  exports.key = {
27
26
  type: Sequelize.STRING,
@@ -36,7 +35,7 @@ exports.key = {
36
35
  msg: 'key值不允许为空',
37
36
  },
38
37
  },
39
- };
38
+ }
40
39
 
41
40
  exports.value = {
42
41
  type: Sequelize.STRING,
@@ -51,4 +50,4 @@ exports.value = {
51
50
  msg: 'value值不允许为空',
52
51
  },
53
52
  },
54
- };
53
+ }
@@ -1,4 +1,4 @@
1
- const { getAppByCtx } = require('multiple-quick-koa')
1
+ const { getAppByCtx } = require('q-koa')
2
2
 
3
3
  exports.clearWeixin = async (ctx) => {
4
4
  const { app } = getAppByCtx(ctx)
@@ -1,4 +1,4 @@
1
- const { Sequelize } = require('multiple-quick-koa')
1
+ const { Sequelize } = require('q-koa')
2
2
 
3
3
  exports.url = {
4
4
  type: Sequelize.STRING,
@@ -1,7 +1,8 @@
1
- const { getAppByCtx, lodash } = require('multiple-quick-koa')
1
+ const { getAppByCtx, lodash } = require('q-koa')
2
2
 
3
3
  const fs = require('fs')
4
4
  const path = require('path')
5
+ const fsPromise = require('fs/promises')
5
6
 
6
7
  exports.getModel = async (ctx) => {
7
8
  const { app, appName } = getAppByCtx(ctx)
@@ -19,7 +20,7 @@ exports.getModel = async (ctx) => {
19
20
  )
20
21
  )
21
22
  if (!existFile) return ctx.SUCCESS('')
22
- const file = fs.readFileSync(
23
+ const file = await fsPromise.readFile(
23
24
  path.resolve(
24
25
  __dirname,
25
26
  `${process.cwd()}/app/${appName}/plugins/${model}/${option}.js`
@@ -54,7 +55,7 @@ exports.createFile = async (ctx) => {
54
55
  `${process.cwd()}/app/${appName}/plugins/${plugin}`
55
56
  )
56
57
  const exist = fs.existsSync(pluginDirPath)
57
- if (!exist) fs.mkdirSync(pluginDirPath)
58
+ if (!exist) await fsPromise.mkdir(pluginDirPath)
58
59
  const list = ['config', 'model', 'controller']
59
60
 
60
61
  for (let i = 0; i < list.length; i++) {
@@ -62,8 +63,10 @@ exports.createFile = async (ctx) => {
62
63
  if (!obj[type]) {
63
64
  continue
64
65
  }
65
- fs.writeFileSync(path.resolve(pluginDirPath, `${type}.js`), obj[type])
66
+ await fsPromise.writeFile(
67
+ path.resolve(pluginDirPath, `${type}.js`),
68
+ obj[type]
69
+ )
66
70
  }
67
- // fs.writeFileSync(path.resolve(pluginDirPath, 'config.js'), desc)
68
71
  ctx.SUCCESS('ok')
69
72
  }
@@ -1,4 +1,4 @@
1
- const { Sequelize } = require('multiple-quick-koa')
1
+ const { Sequelize } = require('q-koa')
2
2
 
3
3
  exports.model = {
4
4
  type: Sequelize.STRING,
@@ -1,12 +1,12 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
-
3
+ const fsPromise = require('fs/promises')
4
4
  exports.loadModel = async ({ app, appName }) => {
5
- const data = fs.readdirSync(
5
+ const data = await fsPromise.readdir(
6
6
  path.resolve(__dirname, `${process.cwd()}/app/${appName}/plugins`)
7
7
  )
8
8
 
9
- const modelList = await app.model.model.findAll({ raw: true })
9
+ // const modelList = await app.model.model.findAll({ raw: true })
10
10
 
11
11
  await Promise.all(
12
12
  ['model', 'model_attributes'].map((item) =>
@@ -34,32 +34,32 @@ exports.loadModel = async ({ app, appName }) => {
34
34
  __dirname,
35
35
  `../${result[i]}/config.js`
36
36
  )
37
-
38
37
  const modelExist = fs.existsSync(filePath)
39
38
  const defaultModelExist = fs.existsSync(defaultFilePath)
40
39
  const configExist = fs.existsSync(configPath)
41
40
  if (configExist) {
42
- const config = fs.readFileSync(configPath, 'utf-8')
41
+ const config = (await fsPromise.readFile(configPath, 'utf-8'))
43
42
  ? require(configPath)
44
43
  : require(defaultConfigPath)
45
44
 
46
45
  const modelFile =
47
46
  defaultModelExist || modelExist
48
- ? fs.readFileSync(filePath, 'utf-8')
49
- ? fs.readFileSync(filePath, 'utf-8')
50
- : fs.readFileSync(defaultFilePath, 'utf-8')
47
+ ? (await fsPromise.readFile(filePath, 'utf-8'))
48
+ ? await fsPromise.readFile(filePath, 'utf-8')
49
+ : await fsPromise.readFile(defaultFilePath, 'utf-8')
51
50
  : null
52
51
 
53
52
  const model = modelFile
54
- ? fs.readFileSync(filePath, 'utf-8')
53
+ ? (await fsPromise.readFile(filePath, 'utf-8'))
55
54
  ? require(filePath)
56
55
  : require(defaultFilePath)
57
56
  : {}
58
57
  const attributes = modelFile ? modelFile.match(/exports.(.*)=/g) : []
59
58
  const types = modelFile ? modelFile.match(/Sequelize.(.*),\n/g) : {}
60
59
 
61
- const ori_target = modelList.find((m) => m.model === result[i])
62
- const id = ori_target ? ori_target.id : null
60
+ // const ori_target = modelList.find((m) => m.model === result[i])
61
+ // const id = ori_target ? ori_target.id : null
62
+ const id = i + 1
63
63
  const obj = {
64
64
  id,
65
65
  model: result[i],
@@ -1,6 +1,4 @@
1
- const {
2
- Validator
3
- } = require('multiple-quick-koa');
1
+ const { Validator } = require('q-koa')
4
2
 
5
3
  exports.getModel = async (ctx) => {
6
4
  const params = {
@@ -9,9 +7,9 @@ exports.getModel = async (ctx) => {
9
7
  required: true,
10
8
  message: '请输入model',
11
9
  },
12
- };
13
- await new Validator(params).validate(ctx.request.body);
14
- };
10
+ }
11
+ await new Validator(params).validate(ctx.request.body)
12
+ }
15
13
 
16
14
  exports.createModel = async (ctx) => {
17
15
  const params = {
@@ -25,10 +23,9 @@ exports.createModel = async (ctx) => {
25
23
  required: true,
26
24
  message: '请输入desc详情',
27
25
  },
28
- };
29
- await new Validator(params).validate(ctx.request.body);
30
- };
31
-
26
+ }
27
+ await new Validator(params).validate(ctx.request.body)
28
+ }
32
29
 
33
30
  exports.createFile = async (ctx) => {
34
31
  const params = {
@@ -37,6 +34,6 @@ exports.createFile = async (ctx) => {
37
34
  required: true,
38
35
  message: '请输入plugin',
39
36
  },
40
- };
41
- await new Validator(params).validate(ctx.request.body);
42
- };
37
+ }
38
+ await new Validator(params).validate(ctx.request.body)
39
+ }
@@ -1,4 +1,4 @@
1
- const { Sequelize, Random } = require('multiple-quick-koa')
1
+ const { Sequelize, Random } = require('q-koa')
2
2
 
3
3
  exports.model_id = {
4
4
  type: Sequelize.INTEGER(11),
@@ -1,4 +1,4 @@
1
- const { Sequelize, Random } = require('multiple-quick-koa')
1
+ const { Sequelize, Random } = require('q-koa')
2
2
 
3
3
  exports.openid = {
4
4
  type: Sequelize.STRING,
@@ -1,4 +1,4 @@
1
- const { Sequelize } = require('multiple-quick-koa')
1
+ const { Sequelize } = require('q-koa')
2
2
 
3
3
  exports.name = {
4
4
  type: Sequelize.STRING,
@@ -1,4 +1,4 @@
1
- const { getAppByCtx } = require('multiple-quick-koa')
1
+ const { getAppByCtx } = require('q-koa')
2
2
 
3
3
  exports.init = async (ctx) => {
4
4
  const { app } = getAppByCtx(ctx)
@@ -1,4 +1,4 @@
1
- const { Sequelize, Random } = require('multiple-quick-koa')
1
+ const { Sequelize, Random } = require('q-koa')
2
2
 
3
3
  exports.name = {
4
4
  type: Sequelize.STRING,
@@ -1,4 +1,4 @@
1
- const { getAppByCtx } = require('multiple-quick-koa')
1
+ const { getAppByCtx } = require('q-koa')
2
2
 
3
3
  exports.edit = async (ctx) => {
4
4
  const { app, appName } = getAppByCtx(ctx)