q-koa 13.1.2 → 13.1.4
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
|
@@ -10,6 +10,7 @@ const moment = require('moment')
|
|
|
10
10
|
const { EventEmitter } = require('events')
|
|
11
11
|
const nodeVm = require('vm')
|
|
12
12
|
const LRU = require('lru-cache')
|
|
13
|
+
const axios = require('axios')
|
|
13
14
|
|
|
14
15
|
const { Serve } = require('static-koa-router')
|
|
15
16
|
|
|
@@ -426,7 +427,8 @@ class APP {
|
|
|
426
427
|
subscriber,
|
|
427
428
|
appConfig: _.defaultsDeep(
|
|
428
429
|
configExist ? require(path.resolve(__dirname, configPath)) : {},
|
|
429
|
-
this.config.app
|
|
430
|
+
this.config.app,
|
|
431
|
+
{ appName, ip: this.config.ip, port: this.port }
|
|
430
432
|
),
|
|
431
433
|
}
|
|
432
434
|
} else {
|
|
@@ -434,7 +436,8 @@ class APP {
|
|
|
434
436
|
sequelize: db,
|
|
435
437
|
appConfig: _.defaultsDeep(
|
|
436
438
|
configExist ? require(path.resolve(__dirname, configPath)) : {},
|
|
437
|
-
this.config.app
|
|
439
|
+
this.config.app,
|
|
440
|
+
{ appName, ip: this.config.ip, port: this.port }
|
|
438
441
|
),
|
|
439
442
|
}
|
|
440
443
|
}
|
|
@@ -2211,6 +2214,26 @@ APP.getConfig = (app) => ({
|
|
|
2211
2214
|
app.redisClient.publish('cache clear', target)
|
|
2212
2215
|
} else {
|
|
2213
2216
|
app.cache.set(target, null)
|
|
2217
|
+
|
|
2218
|
+
if (app.appConfig.appName) {
|
|
2219
|
+
const ipHost = (
|
|
2220
|
+
Array.isArray(app.appConfig.productionHost)
|
|
2221
|
+
? app.appConfig.productionHost
|
|
2222
|
+
: [app.appConfig.productionHost]
|
|
2223
|
+
).filter((url) => {
|
|
2224
|
+
return url.match(
|
|
2225
|
+
/^(http:\/\/|https:\/\/)?(\d{1,3}\.){3}\d{1,3}:\d{1,5}/
|
|
2226
|
+
)
|
|
2227
|
+
})
|
|
2228
|
+
|
|
2229
|
+
Promise.all(
|
|
2230
|
+
ipHost.map((host) => {
|
|
2231
|
+
return axios
|
|
2232
|
+
.get(`${host}/${app.appConfig.appName}/cache/clear?key=${target}`)
|
|
2233
|
+
.then((res) => res.data)
|
|
2234
|
+
})
|
|
2235
|
+
)
|
|
2236
|
+
}
|
|
2214
2237
|
}
|
|
2215
2238
|
},
|
|
2216
2239
|
})
|
|
@@ -604,7 +604,7 @@ exports.gpt = async (ctx) => {
|
|
|
604
604
|
const appConfig = getConfig(app)
|
|
605
605
|
const { ai_key } = await appConfig.getObject('base')
|
|
606
606
|
const { content, session_id, is_chunk = true } = ctx.request.body
|
|
607
|
-
|
|
607
|
+
if (!ai_key) throw new ServiceError('没有配置ai_key')
|
|
608
608
|
if (!content) throw new ServiceError('没有内容content')
|
|
609
609
|
let statusCode = 200
|
|
610
610
|
const url =
|
|
@@ -72,32 +72,44 @@ exports.initModel = async (ctx) => {
|
|
|
72
72
|
return ctx.ERROR('请检查,model为空')
|
|
73
73
|
}
|
|
74
74
|
if (app.appConfig.productionHost) {
|
|
75
|
-
const
|
|
76
|
-
.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
{
|
|
82
|
-
headers: {
|
|
83
|
-
'client-type': 0,
|
|
84
|
-
},
|
|
85
|
-
}
|
|
75
|
+
const productionHost = (
|
|
76
|
+
Array.isArray(app.appConfig.productionHost)
|
|
77
|
+
? app.appConfig.productionHost
|
|
78
|
+
: [app.appConfig.productionHost]
|
|
79
|
+
).filter((url) => {
|
|
80
|
+
return !url.match(
|
|
81
|
+
/^(http:\/\/|https:\/\/)?(\d{1,3}\.){3}\d{1,3}:\d{1,5}/
|
|
86
82
|
)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
for (const host of productionHost) {
|
|
86
|
+
const { code, data: productionModel } = await axios
|
|
87
|
+
.post(
|
|
88
|
+
`${host}/${appName}/system/getTable`,
|
|
89
|
+
{
|
|
90
|
+
model,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
headers: {
|
|
94
|
+
'client-type': 0,
|
|
95
|
+
},
|
|
96
|
+
}
|
|
100
97
|
)
|
|
98
|
+
.then((res) => res.data)
|
|
99
|
+
if (code === 200) {
|
|
100
|
+
const findList = Object.keys(productionModel).filter((key) => {
|
|
101
|
+
return (
|
|
102
|
+
!['id', 'created_at', 'createdid', 'updated_at'].includes(key) &&
|
|
103
|
+
!Object.keys(app.attributes[model]).includes(key)
|
|
104
|
+
)
|
|
105
|
+
})
|
|
106
|
+
if (findList.length > 0) {
|
|
107
|
+
return ctx.ERROR(
|
|
108
|
+
`${model} 线上字段 ${findList.join(
|
|
109
|
+
'/'
|
|
110
|
+
)} 不能被删除,请先修改线上model.js`
|
|
111
|
+
)
|
|
112
|
+
}
|
|
101
113
|
}
|
|
102
114
|
}
|
|
103
115
|
}
|