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
  })
@@ -26,5 +26,8 @@ exports.clear = async (ctx) => {
26
26
  if (!key) return ctx.ERROR('缺key')
27
27
  app.cache.set(key, '')
28
28
 
29
+ const url = `${app.appConfig.ip}:${app.appConfig.port}`
30
+ app.service.log.push({ app, message: `${url}缓存${key}清除` })
31
+
29
32
  ctx.SUCCESS('ok')
30
33
  }
@@ -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 =
@@ -134,6 +134,7 @@ exports.html = async (ctx) => {
134
134
  const { code } = ctx.request.query
135
135
  if (!code) {
136
136
  ctx.body = `没有code`
137
+ return
137
138
  }
138
139
  const target = await app.model.setting.findOne({
139
140
  where: {
@@ -72,32 +72,44 @@ exports.initModel = async (ctx) => {
72
72
  return ctx.ERROR('请检查,model为空')
73
73
  }
74
74
  if (app.appConfig.productionHost) {
75
- const { code, data: productionModel } = await axios
76
- .post(
77
- `${app.appConfig.productionHost}/${appName}/system/getTable`,
78
- {
79
- model,
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
- .then((res) => res.data)
88
- if (code === 200) {
89
- const findList = Object.keys(productionModel).filter((key) => {
90
- return (
91
- !['id', 'created_at', 'createdid', 'updated_at'].includes(key) &&
92
- !Object.keys(app.attributes[model]).includes(key)
93
- )
94
- })
95
- if (findList.length > 0) {
96
- return ctx.ERROR(
97
- `${model} 线上字段 ${findList.join(
98
- '/'
99
- )} 不能被删除,请先修改线上model.js`
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "13.1.2",
3
+ "version": "13.1.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {