q-koa 13.8.46 → 13.8.48

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
@@ -587,11 +587,16 @@ class APP {
587
587
  } catch (e) {
588
588
  push({
589
589
  appName,
590
- message: `${appName}数据库连接失败`,
590
+ message: `${appName}启动失败:${e.message}`,
591
591
  })
592
- console.log(`${appName}数据库连接失败`)
592
+ console.log(chalk.red(`${appName}启动失败,跳过该应用并继续启动后续应用`))
593
593
  console.log(e)
594
- throw new Error(e.message)
594
+ // 清理可能已部分初始化的 app 对象,避免残留不完整状态
595
+ if (this.app[appName]) {
596
+ delete this.app[appName]
597
+ }
598
+ // 不抛出错误,跳过该应用的路由注册,继续启动后续应用
599
+ continue
595
600
  }
596
601
  if (
597
602
  this.app[appName] &&
@@ -232,87 +232,6 @@ exports.channel = async (ctx) => {
232
232
  }
233
233
  }
234
234
 
235
- exports.swagger = async (ctx) => {
236
- const { app, appName } = getAppByCtx(ctx)
237
- if (app.cache && app.cache.get('swagger'))
238
- return ctx.SUCCESS(app.cache.get('swagger'))
239
-
240
- const filePath = path.resolve(
241
- __dirname,
242
- `${process.cwd()}/app/${appName}/plugins`
243
- )
244
- const apis = []
245
- const pathList = await fsPromise.readdir(filePath)
246
- for (let i = 0; i < pathList.length; i++) {
247
- const folder = pathList[i]
248
- const isFolder = fs.lstatSync(path.resolve(filePath, folder)).isDirectory()
249
- if (isFolder) {
250
- const models = []
251
- if (app.model[folder]) {
252
- const result = await app.sequelize
253
- .getQueryInterface()
254
- .describeTable(folder)
255
- Object.keys(result).forEach((attr) => {
256
- models.push(lodash.merge(app.attributes[folder][attr], result[attr]))
257
- // models[attr] = lodash.merge(app.attributes[folder][attr], result[attr]);
258
- })
259
- }
260
-
261
- const controllers = []
262
- const controllerFilePath = path.resolve(filePath, folder, 'controller.js')
263
- const isControllerExist = fs.existsSync(controllerFilePath)
264
- if (isControllerExist) {
265
- const controllerFile = await fsPromise.readFile(
266
- controllerFilePath,
267
- 'utf-8'
268
- )
269
- const annotations = controllerFile.match(annotationsReg)
270
-
271
- if (annotations) {
272
- for (let j = 0; j < annotations.length; j++) {
273
- const annotation = annotations[j]
274
- let res
275
- const obj = {}
276
- while ((res = apiReg.exec(annotation))) {
277
- res = res.map((item) => item.toLowerCase())
278
- if (res[1] === 'param') {
279
- const arr = res[3].split('/')
280
- if (obj[res[1]]) {
281
- obj[res[1]].push({
282
- key: arr[0],
283
- type: arr[1],
284
- name: arr[2],
285
- })
286
- } else {
287
- obj[res[1]] = []
288
-
289
- obj[res[1]].push({
290
- key: arr[0],
291
- type: arr[1],
292
- name: arr[2],
293
- })
294
- }
295
- } else {
296
- obj[res[1]] = res[3]
297
- }
298
- }
299
- controllers.push(obj)
300
- }
301
- }
302
- }
303
- apis.push({
304
- name: folder,
305
- desc: lodash.get(app, `config.${folder}.name`, `${folder}`),
306
- models,
307
- controllers,
308
- })
309
- }
310
- }
311
- app.cache && app.cache.set('swagger', apis)
312
- // console.log(dir)
313
- ctx.SUCCESS(apis)
314
- }
315
-
316
235
  exports.getLocation = async (ctx, _data) => {
317
236
  const { app } = getAppByCtx(ctx)
318
237
 
@@ -64,9 +64,7 @@ exports.push = async ({ app, appName = '通知', url, message }) => {
64
64
  }),
65
65
  ...(logo_image || logo_img
66
66
  ? {
67
- icon: encodeURIComponent(
68
- (logo_image || logo_img).replace('http', 'https')
69
- ),
67
+ icon: logo_image || logo_img,
70
68
  }
71
69
  : {}),
72
70
  }
@@ -215,22 +215,6 @@ exports.initModel = async (ctx) => {
215
215
  return ctx.ERROR(`app.model没有${model}`)
216
216
  }
217
217
  }
218
-
219
- exports.customRouter = async (ctx) => {
220
- // const {
221
- // app,
222
- // appName,
223
- // } = getAppByCtx(ctx);
224
-
225
- // const list = [{
226
- // path: 'jiangong_statis',
227
- // name: '数据面板'
228
- // }]
229
- const list = []
230
- ctx.SUCCESS(list)
231
- return list
232
- }
233
-
234
218
  exports.showTables = async (ctx, _data) => {
235
219
  const { app, appName } = getAppByCtx(ctx)
236
220
  const { omit = [] } = _data || ctx.request.body
@@ -666,21 +650,6 @@ exports.chat = async (ctx) => {
666
650
  }
667
651
  }
668
652
 
669
- exports.dashboard = async (ctx) => {
670
- // const {
671
- // app,
672
- // } = getAppByCtx(ctx);
673
-
674
- const result = [
675
- // {
676
- // name: '用户',
677
- // number: 5,
678
- // route: 'page/user'
679
- // }
680
- ]
681
- ctx.SUCCESS(result)
682
- }
683
-
684
653
  exports.showModelCount = async (ctx) => {
685
654
  const { app, appName } = getAppByCtx(ctx)
686
655
  const { is_count = false } = ctx.request.body
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "13.8.46",
3
+ "version": "13.8.48",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {