q-koa 8.2.1 → 8.3.0

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
@@ -18,6 +18,7 @@ const chalk = require('chalk')
18
18
  const { Random } = require('mockjs')
19
19
  const util = require('util')
20
20
  const jwt = require('jsonwebtoken')
21
+ const verify = util.promisify(jwt.verify)
21
22
  const fsExtra = require('fs-extra')
22
23
  const { getObject } = require('./file/utils')
23
24
  const restc = require('./restc')
@@ -131,10 +132,12 @@ class APP {
131
132
  * jwt中间件
132
133
  */
133
134
  this.app.use(async (ctx, next) => {
134
- const verify = util.promisify(jwt.verify)
135
135
  const { url, host, ip, method } = ctx.request
136
136
 
137
- if (ctx.request.header['user-agent'] && ctx.request.header['user-agent'].startsWith('Tencent Security')) {
137
+ if (
138
+ ctx.request.header['user-agent'] &&
139
+ ctx.request.header['user-agent'].startsWith('Tencent Security')
140
+ ) {
138
141
  return ctx.ERROR('error')
139
142
  }
140
143
  if (this.config.blackList.includes(ip)) {
@@ -5,6 +5,11 @@ const { VM } = require('vm2')
5
5
  const axios = require('axios')
6
6
  const cheerio = require('cheerio')
7
7
  const { lodash, getAppByCtx, getConfig, Sequelize } = require('q-koa')
8
+ const LRU = require('lru-cache')
9
+ const cache = new LRU({
10
+ max: 10,
11
+ maxAge: 1000 * 60 * 60,
12
+ })
8
13
 
9
14
  exports.initModel = async (ctx) => {
10
15
  const { app } = getAppByCtx(ctx)
@@ -306,14 +311,25 @@ exports.showAllSchemas = async (ctx) => {
306
311
 
307
312
  exports.initDataWithCache = exports.initData = async (ctx) => {
308
313
  const { app } = getAppByCtx(ctx)
314
+ const appConfig = getConfig(app)
315
+
316
+ const { is_cache } = await appConfig.getObject('base')
309
317
  const { includes, excludes = [] } = ctx.request.body
310
- const result = await app.service.system.initData({
311
- app,
312
- includes,
313
- excludes,
314
- ctx,
315
- })
316
318
 
319
+ const cacheTarget = JSON.stringify(ctx.request.body)
320
+ if (is_cache && cache.get(cacheTarget)) {
321
+ result = cache.get(cacheTarget)
322
+ } else {
323
+ result = await app.service.system.initData({
324
+ app,
325
+ includes,
326
+ excludes,
327
+ ctx,
328
+ })
329
+ if (is_cache && cacheTarget.includes('setting/findAll')) {
330
+ cache.set(cacheTarget, result)
331
+ }
332
+ }
317
333
  return ctx.SUCCESS(result)
318
334
  }
319
335
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "8.2.1",
3
+ "version": "8.3.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {