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
@@ -1,7 +1,8 @@
1
- const { getAppByCtx, getConfig } = require('multiple-quick-koa')
1
+ const { getAppByCtx, getConfig } = require('q-koa')
2
2
  const { Pay } = require('@sigodenjs/wechatpay')
3
3
  const fs = require('fs')
4
4
  const path = require('path')
5
+ const fsPromise = require('fs/promises')
5
6
 
6
7
  exports.refund = async ({
7
8
  ctx,
@@ -21,7 +22,7 @@ exports.refund = async ({
21
22
  appId: appId,
22
23
  mchId: mchId,
23
24
  key: key, // 微信商户平台API密钥,
24
- pfx: fs.readFileSync(
25
+ pfx: await fsPromise.readFile(
25
26
  path.resolve(
26
27
  __dirname,
27
28
  `${process.cwd()}/app/${appName}/plugins/weixin/apiclient_cert.p12`
@@ -71,7 +72,7 @@ exports.cash = async ({ ctx, id, user_id, number }) => {
71
72
  appId: appId,
72
73
  mchId: mchId,
73
74
  key: key, // 微信商户平台API密钥,
74
- pfx: fs.readFileSync(
75
+ pfx: await fsPromise.readFile(
75
76
  path.resolve(
76
77
  __dirname,
77
78
  `${process.cwd()}/app/${appName}/plugins/weixin/apiclient_cert.p12`
@@ -1,4 +1,4 @@
1
- const { Validator } = require('multiple-quick-koa');
1
+ const { Validator } = require('q-koa')
2
2
 
3
3
  exports.getConfig = async (ctx) => {
4
4
  const params = {
@@ -7,27 +7,27 @@ exports.getConfig = async (ctx) => {
7
7
  required: true,
8
8
  message: '请输入url',
9
9
  },
10
- };
11
- await new Validator(params).validate(ctx.request.body);
12
- };
10
+ }
11
+ await new Validator(params).validate(ctx.request.body)
12
+ }
13
13
 
14
14
  exports.h5_pay = async (ctx) => {
15
15
  /**
16
16
  * 判断微信
17
17
  */
18
- const userAgent = ctx.userAgent._agent.source;
19
- const isWeixin = /MicroMessenger/i.test(userAgent);
20
- if (isWeixin) throw new Error('请用手机浏览器打开');
21
- };
18
+ const userAgent = ctx.userAgent._agent.source
19
+ const isWeixin = /MicroMessenger/i.test(userAgent)
20
+ if (isWeixin) throw new Error('请用手机浏览器打开')
21
+ }
22
22
 
23
23
  exports.wx_pay = async (ctx) => {
24
24
  /**
25
25
  * 判断微信
26
26
  */
27
- const userAgent = ctx.userAgent._agent.source;
28
- const isWeixin = /MicroMessenger/i.test(userAgent);
29
- if (!isWeixin) throw new Error('请在微信里打开');
30
- };
27
+ const userAgent = ctx.userAgent._agent.source
28
+ const isWeixin = /MicroMessenger/i.test(userAgent)
29
+ if (!isWeixin) throw new Error('请在微信里打开')
30
+ }
31
31
 
32
32
  exports.pay = async (ctx) => {
33
33
  const params = {
@@ -46,9 +46,9 @@ exports.pay = async (ctx) => {
46
46
  required: 1,
47
47
  message: '请输入支付金额',
48
48
  },
49
- };
50
- await new Validator(params).validate(ctx.request.body);
51
- };
49
+ }
50
+ await new Validator(params).validate(ctx.request.body)
51
+ }
52
52
 
53
53
  exports.mp_login = async (ctx) => {
54
54
  const params = {
@@ -57,10 +57,9 @@ exports.mp_login = async (ctx) => {
57
57
  required: true,
58
58
  message: '需要code登录',
59
59
  },
60
- };
61
- await new Validator(params).validate(ctx.request.body);
62
- };
63
-
60
+ }
61
+ await new Validator(params).validate(ctx.request.body)
62
+ }
64
63
 
65
64
  exports.qr_code = async (ctx) => {
66
65
  const params = {
@@ -79,10 +78,9 @@ exports.qr_code = async (ctx) => {
79
78
  required: false,
80
79
  message: 'scene 参数 object',
81
80
  },
82
- };
83
- await new Validator(params).validate(ctx.request.body);
84
- };
85
-
81
+ }
82
+ await new Validator(params).validate(ctx.request.body)
83
+ }
86
84
 
87
85
  exports.sendMessage = async (ctx) => {
88
86
  const params = {
@@ -99,13 +97,14 @@ exports.sendMessage = async (ctx) => {
99
97
  data: {
100
98
  type: 'object',
101
99
  required: true,
102
- message: 'data | {name1:{value:\'苏晓光\'},number2:{value:\'32323\'},thing5:{value:\'xxx\'}}',
100
+ message:
101
+ "data | {name1:{value:'苏晓光'},number2:{value:'32323'},thing5:{value:'xxx'}}",
103
102
  },
104
103
  page: {
105
104
  type: 'string',
106
105
  required: false,
107
106
  message: '请输入页面链接:pages/index/index',
108
107
  },
109
- };
110
- await new Validator(params).validate(ctx.request.body);
111
- };
108
+ }
109
+ await new Validator(params).validate(ctx.request.body)
110
+ }
@@ -1,45 +1,46 @@
1
- const Core = require('@alicloud/pop-core');
2
- const {
3
- lodash
4
- } = require('multiple-quick-koa')
1
+ const Core = require('@alicloud/pop-core')
2
+ const { lodash } = require('q-koa')
5
3
  module.exports = class Sms {
6
- constructor (config) {
4
+ constructor(config) {
7
5
  this.config = {
8
6
  accessKeyId: config.accessKeyId, // 开发者账号id
9
7
  accessKeySecret: config.accessKeySecret, // 开发者token
10
8
  SignName: config.SignName, // 应用id
11
- param: Array.from({
12
- length: config.number || 4
13
- }, () => lodash.random(0, 9)).join(''),
14
- };
9
+ param: Array.from(
10
+ {
11
+ length: config.number || 4,
12
+ },
13
+ () => lodash.random(0, 9)
14
+ ).join(''),
15
+ }
15
16
  this.client = new Core({
16
17
  accessKeyId: this.config.accessKeyId,
17
18
  accessKeySecret: this.config.accessKeySecret,
18
19
  endpoint: 'https://dysmsapi.aliyuncs.com',
19
- apiVersion: '2017-05-25'
20
- });
20
+ apiVersion: '2017-05-25',
21
+ })
21
22
  }
22
23
 
23
- async send ({
24
- mobile,
25
- TemplateCode,
26
- TemplateParam
27
- }) {
24
+ async send({ mobile, TemplateCode, TemplateParam }) {
28
25
  // if(!mobile) throw new Error('请输入手机号码')
29
- const result = await this.client.request('SendSms', {
30
- PhoneNumbers: mobile,
31
- SignName: this.config.SignName,
32
- TemplateCode,
33
- TemplateParam: JSON.stringify({
34
- code: this.config.param
35
- })
36
- }, {
37
- method: 'POST'
38
- })
26
+ const result = await this.client.request(
27
+ 'SendSms',
28
+ {
29
+ PhoneNumbers: mobile,
30
+ SignName: this.config.SignName,
31
+ TemplateCode,
32
+ TemplateParam: JSON.stringify({
33
+ code: this.config.param,
34
+ }),
35
+ },
36
+ {
37
+ method: 'POST',
38
+ }
39
+ )
39
40
  return result
40
41
  }
41
42
 
42
- getCode () {
43
+ getCode() {
43
44
  return this.config.param
44
45
  }
45
- };
46
+ }
@@ -1,5 +1,5 @@
1
1
  const crypto = require('crypto')
2
- const { lodash } = require('multiple-quick-koa')
2
+ const { lodash } = require('q-koa')
3
3
  module.exports = class Singleton {
4
4
  constructor(config) {
5
5
  this.config = {
@@ -1,5 +1,5 @@
1
1
  const axios = require('axios')
2
- const { lodash } = require('multiple-quick-koa')
2
+ const { lodash } = require('q-koa')
3
3
 
4
4
  const queryFn = (obj) => {
5
5
  const query = Object.keys(obj)
@@ -10,7 +10,7 @@ const queryFn = (obj) => {
10
10
  return query.replace('&', '?')
11
11
  }
12
12
  module.exports = class Singleton {
13
- constructor (key) {
13
+ constructor(key) {
14
14
  this.key = key
15
15
 
16
16
  /**
@@ -26,7 +26,7 @@ module.exports = class Singleton {
26
26
  return Singleton.instance
27
27
  }
28
28
 
29
- async geo ({ address }) {
29
+ async geo({ address }) {
30
30
  if (!this.key) throw new Error('没有key')
31
31
 
32
32
  const obj = {
@@ -43,7 +43,7 @@ module.exports = class Singleton {
43
43
  return data.geocodes
44
44
  }
45
45
 
46
- async regeo ({ longitude, latitude }) {
46
+ async regeo({ longitude, latitude }) {
47
47
  if (!this.key) throw new Error('没有key')
48
48
 
49
49
  const obj = {
@@ -60,7 +60,7 @@ module.exports = class Singleton {
60
60
  return data
61
61
  }
62
62
 
63
- async getDistrict ({
63
+ async getDistrict({
64
64
  keywords,
65
65
  subdistrict,
66
66
  page,
@@ -89,7 +89,7 @@ module.exports = class Singleton {
89
89
  return data
90
90
  }
91
91
 
92
- getConfig () {
92
+ getConfig() {
93
93
  return this.key
94
94
  }
95
95
  }
@@ -1,6 +1,6 @@
1
1
  const util = require('util')
2
2
  const axios = require('axios')
3
- const { lodash } = require('multiple-quick-koa')
3
+ const { lodash } = require('q-koa')
4
4
 
5
5
  const commonTokenUrl =
6
6
  'https://open.douyin.com/oauth/client_token/?client_key=%s&client_secret=%s&grant_type=client_credential'
@@ -1,8 +1,8 @@
1
1
  const axios = require('axios')
2
- const { lodash } = require('multiple-quick-koa')
2
+ const { lodash } = require('q-koa')
3
3
  const send_url = 'http://wuliu.market.alicloudapi.com/kdi'
4
4
  module.exports = class Singleton {
5
- constructor (config) {
5
+ constructor(config) {
6
6
  this.config = {
7
7
  app_code: config.app_code,
8
8
  }
@@ -20,7 +20,7 @@ module.exports = class Singleton {
20
20
  return Singleton.instance
21
21
  }
22
22
 
23
- async send ({ no }) {
23
+ async send({ no }) {
24
24
  const result = await axios({
25
25
  method: 'GET',
26
26
  url: `${send_url}?no=${no}`,
@@ -31,7 +31,7 @@ module.exports = class Singleton {
31
31
  return result.result
32
32
  }
33
33
 
34
- getConfig () {
34
+ getConfig() {
35
35
  return this.config
36
36
  }
37
37
  }
@@ -1,6 +1,6 @@
1
1
  const axios = require('axios')
2
2
  const util = require('util')
3
- const { lodash } = require('multiple-quick-koa')
3
+ const { lodash } = require('q-koa')
4
4
  const toLocationUrl =
5
5
  'https://apis.map.qq.com/ws/geocoder/v1/?location=%s&key=%s'
6
6
  const toLngAndLatUrl =
@@ -1,7 +1,7 @@
1
1
  const util = require('util')
2
2
  const axios = require('axios')
3
-
4
- const { lodash } = require('multiple-quick-koa')
3
+ const fsPromise = require('fs/promises')
4
+ const { lodash } = require('q-koa')
5
5
  const getAccessTokenUrl =
6
6
  'https://developer.toutiao.com/api/apps/token?grant_type=%s&appid=%s&secret=%s'
7
7
  const createQRCodeUrl = 'https://developer.toutiao.com/api/apps/qrcode'
@@ -88,7 +88,7 @@ module.exports = class Singleton {
88
88
  }
89
89
  throw new Error(bufferResult.errmsg)
90
90
  }
91
- await fs.writeFileSync(
91
+ await fsPromise.writeFile(
92
92
  `${this.config.targetPath}/${creatuuid}.png`,
93
93
  bufferResult
94
94
  )
@@ -1,16 +1,15 @@
1
1
  const util = require('util')
2
2
  const axios = require('axios')
3
3
  const getAccessTokenUrl = `https://api.weixin.qq.com/cgi-bin/token?grant_type=%s&appid=%s&secret=%s`
4
- const getTicketUrl = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi'
4
+ const getTicketUrl =
5
+ 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi'
5
6
  const sha1 = require('sha1')
6
7
  const LRU = require('lru-cache')
7
8
  const cache = new LRU({
8
9
  max: 100,
9
- maxAge: 1000 * 60 * 60
10
+ maxAge: 1000 * 60 * 60,
10
11
  })
11
- const {
12
- lodash
13
- } = require('multiple-quick-koa')
12
+ const { lodash } = require('q-koa')
14
13
 
15
14
  module.exports = class Singleton {
16
15
  constructor(config) {
@@ -24,7 +23,7 @@ module.exports = class Singleton {
24
23
  * 单例模式
25
24
  */
26
25
  if (!Singleton.instance) {
27
- Singleton.instance = this
26
+ Singleton.instance = this
28
27
  }
29
28
  const previous = Singleton.instance.getConfig()
30
29
  if (!lodash.isEqual(previous, config)) {
@@ -33,7 +32,8 @@ module.exports = class Singleton {
33
32
  return Singleton.instance
34
33
  }
35
34
  init() {
36
- if (!this.config.appid || !this.config.secrect) throw new Error('没有配置appid或secrect')
35
+ if (!this.config.appid || !this.config.secrect)
36
+ throw new Error('没有配置appid或secrect')
37
37
  }
38
38
  async getAccessToken() {
39
39
  const { appid, secrect, grant_type } = this.config
@@ -41,7 +41,7 @@ module.exports = class Singleton {
41
41
  return cache.get('access_token')
42
42
  }
43
43
  const url = util.format(getAccessTokenUrl, grant_type, appid, secrect)
44
- const result = await axios.get(url).then(res => res.data)
44
+ const result = await axios.get(url).then((res) => res.data)
45
45
  if (result.errcode) throw new Error(result.errmsg)
46
46
 
47
47
  cache.set('access_token', result.access_token)
@@ -51,7 +51,7 @@ module.exports = class Singleton {
51
51
  async getTicket() {
52
52
  const access_token = await this.getAccessToken()
53
53
  const url = util.format(getTicketUrl, access_token)
54
- const result = await axios.get(url).then(res => res.data)
54
+ const result = await axios.get(url).then((res) => res.data)
55
55
  if (result.errcode) throw new Error(result.errmsg)
56
56
 
57
57
  cache.set('ticket', result.ticket)
@@ -68,12 +68,21 @@ module.exports = class Singleton {
68
68
  timestamp,
69
69
  url,
70
70
  jsapi_ticket,
71
- signature: sha1('jsapi_ticket=' + jsapi_ticket + '&noncestr=' + noncestr + '&timestamp=' + timestamp + '&url=' + url)
71
+ signature: sha1(
72
+ 'jsapi_ticket=' +
73
+ jsapi_ticket +
74
+ '&noncestr=' +
75
+ noncestr +
76
+ '&timestamp=' +
77
+ timestamp +
78
+ '&url=' +
79
+ url
80
+ ),
72
81
  }
73
82
  return result
74
83
  }
75
84
 
76
- getConfig () {
85
+ getConfig() {
77
86
  return this.config
78
87
  }
79
- }
88
+ }
@@ -1,7 +1,7 @@
1
1
  const util = require('util')
2
2
  const axios = require('axios')
3
3
 
4
- const { lodash } = require('multiple-quick-koa')
4
+ const { lodash } = require('q-koa')
5
5
  const getAccessTokenUrl =
6
6
  'https://api.weixin.qq.com/cgi-bin/token?grant_type=%s&appid=%s&secret=%s'
7
7
  const createQRCodeUrl =
@@ -31,6 +31,7 @@ const addOrderUrl =
31
31
 
32
32
  const path = require('path')
33
33
  const fs = require('fs')
34
+ const fsPromise = require('fs/promises')
34
35
  const LRU = require('lru-cache')
35
36
  const request = require('request')
36
37
  const cache = new LRU({
@@ -313,7 +314,7 @@ module.exports = class Singleton {
313
314
  }
314
315
  throw new Error(bufferResult.errmsg)
315
316
  }
316
- await fs.writeFileSync(
317
+ await fsPromise.writeFile(
317
318
  `${this.config.targetPath}/${creatuuid}.png`,
318
319
  bufferResult
319
320
  )
@@ -1,4 +1,4 @@
1
- const { lodash } = require('multiple-quick-koa')
1
+ const { lodash } = require('q-koa')
2
2
 
3
3
  exports.getSetting = (config) => (type) =>
4
4
  config.find((i) => i.key === type).value
@@ -4,7 +4,10 @@ const fs = require('fs')
4
4
  const path = require('path')
5
5
  const Gateway = require('./utils/gateway.js')
6
6
 
7
- const content = fs.readFileSync(path.join(__dirname, '../faas/index.html'), 'utf-8')
7
+ const content = fs.readFileSync(
8
+ path.join(__dirname, '../faas/index.html'),
9
+ 'utf-8'
10
+ )
8
11
 
9
12
  const cache = new WeakMap()
10
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "7.7.3",
3
+ "version": "7.7.8",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {