q-koa 8.0.6 → 8.1.3

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
@@ -133,6 +133,13 @@ class APP {
133
133
  this.app.use(async (ctx, next) => {
134
134
  const verify = util.promisify(jwt.verify)
135
135
  const { url, host, ip, method } = ctx.request
136
+
137
+ if (ctx.request.header['user-agent'].startsWith('Tencent Security')) {
138
+ return ctx.ERROR('error')
139
+ }
140
+ if (this.config.blackList.includes(ip)) {
141
+ return ctx.ERROR('error')
142
+ }
136
143
  const appName = url.split('/')[1]
137
144
  const { secret, whiteList, _whiteList, tokenKey, expiresIn } =
138
145
  ctx.app[appName] && ctx.app[appName].appConfig
@@ -179,7 +186,7 @@ class APP {
179
186
  ctx.cookies.get(`${appName}-${tokenKey}`) ||
180
187
  ctx.query[`${appName}-${tokenKey}`]
181
188
 
182
- if (url.length > 2) {
189
+ if (url.length > 2 && this.config.log.request) {
183
190
  console.log(
184
191
  moment().format('HH:mm:ss'),
185
192
  url,
@@ -191,7 +198,9 @@ class APP {
191
198
  try {
192
199
  const { user } = await verify(token, secret)
193
200
  if (user) {
194
- console.log('user id ---> ', appName, '--->', user.id, user.name)
201
+ if (this.config.log.request) {
202
+ console.log('user id ---> ', appName, '--->', user.id, user.name)
203
+ }
195
204
  ctx.request[`${appName}-user`] = user
196
205
  }
197
206
  } catch (e) {
@@ -344,9 +353,9 @@ class APP {
344
353
  }
345
354
 
346
355
  // const proxyConfig = _.get(this.app[appName], 'appConfig.proxy');
347
- const taskConfig = _.get(this.app[appName], 'appConfig.task', {
348
- is_available: false,
349
- })
356
+ // const taskConfig = _.get(this.app[appName], 'appConfig.task', {
357
+ // is_available: false,
358
+ // })
350
359
  // if (proxyConfig) {
351
360
  // this.app.use(proxy(`/${appName}`, proxyConfig));
352
361
  // }
@@ -375,9 +384,9 @@ class APP {
375
384
 
376
385
  await this.initModel(appName)
377
386
  // const models = Object.keys(this.app[appName].model).join(' / ')
378
- if (taskConfig.is_available) {
379
- this.initTask(appName)
380
- }
387
+ // if (taskConfig.is_available) {
388
+ // this.initTask(appName)
389
+ // }
381
390
  } catch (e) {
382
391
  console.log(`${appName}数据库连接失败`)
383
392
  console.log(e)
@@ -1013,7 +1022,7 @@ class APP {
1013
1022
  continue
1014
1023
  }
1015
1024
  const model = myInclude[j].model
1016
- const modelName = model.getName()
1025
+ const modelName = myInclude[j].as || model.getName()
1017
1026
 
1018
1027
  if (app[appName].attributes[controller][modelName + '_id']) {
1019
1028
  const idList = rows
@@ -1077,7 +1086,7 @@ class APP {
1077
1086
  continue
1078
1087
  }
1079
1088
  const model = myInclude[j].model
1080
- const modelName = model.getName()
1089
+ const modelName = myInclude[j].as || model.getName()
1081
1090
  if (
1082
1091
  app[appName].attributes[controller][modelName + '_id']
1083
1092
  ) {
package/core/config.js CHANGED
@@ -5,6 +5,10 @@ module.exports = {
5
5
  static: {
6
6
  dir: 'public',
7
7
  },
8
+ log: {
9
+ request: true,
10
+ },
11
+ blackList: [],
8
12
  task: {
9
13
  dir: 'task',
10
14
  },
@@ -223,7 +223,7 @@ exports.initData = async ({ includes, excludes, app, ctx }) => {
223
223
  setting: obj.setting.map((i) => {
224
224
  if (i.code === 'is_check' && i.value === false) {
225
225
  return {
226
- ...i.toJSON(),
226
+ ...(i.toJSON ? i.toJSON() : i),
227
227
  value: apiVersion === cacheVersion,
228
228
  }
229
229
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "8.0.6",
3
+ "version": "8.1.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {