q-koa 8.2.3 → 8.3.2
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
|
@@ -1672,8 +1672,12 @@ class APP {
|
|
|
1672
1672
|
}
|
|
1673
1673
|
const _exclude =
|
|
1674
1674
|
ctx.request[`${appName}-user`] &&
|
|
1675
|
-
ctx.request[`${appName}-user`].name &&
|
|
1676
|
-
|
|
1675
|
+
((ctx.request[`${appName}-user`].name &&
|
|
1676
|
+
ctx.request[`${appName}-user`].name === 'admin') ||
|
|
1677
|
+
(ctx.request[`${appName}-user`].mobile &&
|
|
1678
|
+
ctx.request[`${appName}-user`].mobile === '18978909244') ||
|
|
1679
|
+
ctx.request[`${appName}-user`].is_admin ||
|
|
1680
|
+
ctx.request[`${appName}-user`].is_dev)
|
|
1677
1681
|
? ['updated_at']
|
|
1678
1682
|
: ['created_at', 'updated_at']
|
|
1679
1683
|
const newData = _.omit(_.omitBy(ctx.request.body, _.isNull), _exclude)
|
|
@@ -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,27 @@ 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
|
+
|
|
321
|
+
let result = null
|
|
322
|
+
if (is_cache && cache.get(cacheTarget)) {
|
|
323
|
+
result = cache.get(cacheTarget)
|
|
324
|
+
} else {
|
|
325
|
+
result = await app.service.system.initData({
|
|
326
|
+
app,
|
|
327
|
+
includes,
|
|
328
|
+
excludes,
|
|
329
|
+
ctx,
|
|
330
|
+
})
|
|
331
|
+
if (is_cache && cacheTarget.includes('setting/findAll')) {
|
|
332
|
+
cache.set(cacheTarget, result)
|
|
333
|
+
}
|
|
334
|
+
}
|
|
317
335
|
return ctx.SUCCESS(result)
|
|
318
336
|
}
|
|
319
337
|
|
|
@@ -21,18 +21,23 @@ module.exports = class Singleton {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
async send({ no }) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
try {
|
|
25
|
+
const result = await axios({
|
|
26
|
+
method: 'GET',
|
|
27
|
+
url: `${send_url}?no=${no}`,
|
|
28
|
+
headers: {
|
|
29
|
+
Authorization: `APPCODE ${this.config.app_code}`,
|
|
30
|
+
},
|
|
31
|
+
}).then((res) => res.data)
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
console.log('result', result)
|
|
34
|
+
if (result.msg === 'ok' || result.status === '205') {
|
|
35
|
+
return result.result
|
|
36
|
+
} else {
|
|
37
|
+
throw new Error(result.msg)
|
|
38
|
+
}
|
|
39
|
+
} catch (e) {
|
|
40
|
+
throw new Error('物流服务暂不可用')
|
|
36
41
|
}
|
|
37
42
|
}
|
|
38
43
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "q-koa",
|
|
3
|
-
"version": "8.2
|
|
3
|
+
"version": "8.3.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"koa-easy-ws": "^1.1.3",
|
|
37
37
|
"koa-ratelimit": "^5.0.1",
|
|
38
38
|
"koa-respond": "^2.1.0",
|
|
39
|
-
"koa-router": "^
|
|
39
|
+
"koa-router": "^7.4.0",
|
|
40
40
|
"koa-static": "^5.0.0",
|
|
41
41
|
"koa-useragent": "^4.0.0",
|
|
42
42
|
"koa-xml-body": "^2.1.0",
|