q-koa 8.9.5 → 9.0.3

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/config.js CHANGED
@@ -132,6 +132,9 @@ module.exports = {
132
132
  },
133
133
  cacheModel: [],
134
134
  defaultRouter: (router) => (app) => {
135
+ router.get('/cache/get', app.controller.cache.get)
136
+ router.get('/cache/clear', app.controller.cache.clear)
137
+
135
138
  router.get('/weixin/h5_login', app.controller.weixin.h5_login)
136
139
  router.get(
137
140
  '/weixin/h5_login_callback',
@@ -0,0 +1,23 @@
1
+ const { getAppByCtx, getUserByCtx, getConfig } = require('q-koa')
2
+
3
+ exports.get = async (ctx) => {
4
+ const { app, appName } = getAppByCtx(ctx)
5
+ const key =
6
+ ctx.request.method === 'POST' ? ctx.request.body.key : ctx.query.key
7
+
8
+ if (!key) return ctx.ERROR('缺key')
9
+ const result = app.cache.get(key)
10
+
11
+ ctx.SUCCESS(result || '')
12
+ }
13
+
14
+ exports.clear = async (ctx) => {
15
+ const { app, appName } = getAppByCtx(ctx)
16
+ const key =
17
+ ctx.request.method === 'POST' ? ctx.request.body.key : ctx.query.key
18
+
19
+ if (!key) return ctx.ERROR('缺key')
20
+ app.cache.set(key, '')
21
+
22
+ ctx.SUCCESS('ok')
23
+ }
@@ -96,8 +96,15 @@ exports.initRoute = async (ctx) => {
96
96
  },
97
97
  ]
98
98
 
99
- const permissionList = await app.model.permission.findAll()
100
- const modelList = await app.model.model.findAll()
99
+ const permissionList = await app.model.permission.findAll({
100
+ attributes: ['id', 'name', 'controller'],
101
+ raw: true,
102
+ })
103
+ const modelList = await app.model.model.findAll({
104
+ attributes: ['id', 'belongs', 'model'],
105
+ raw: true,
106
+ })
107
+
101
108
  const roleList = await app.model.role.findAll()
102
109
  const rolePermission = lodash.uniq(
103
110
  roleList
@@ -105,7 +112,7 @@ exports.initRoute = async (ctx) => {
105
112
  .reduce((a, b) => [...a, ...b.permission_id], [])
106
113
  )
107
114
  for (let i = 0; i < permissionList.length; i++) {
108
- const target = permissionList[i].toJSON()
115
+ const target = permissionList[i]
109
116
  if (target.controller === '') {
110
117
  await app.model.permission.destroy({
111
118
  where: {
@@ -128,18 +135,20 @@ exports.initRoute = async (ctx) => {
128
135
  const is_project = !model
129
136
  list = [
130
137
  ...list,
131
- {
132
- name: target.name,
133
- parent_id,
134
- url: is_project ? `/project/${appName}/` + target.controller : '',
135
- model_id: model ? model.id : 0,
136
- key: is_project
137
- ? ''
138
- : model && model.belongs
139
- ? `${model.belongs}/${model.model}`
140
- : '',
141
- },
142
- ]
138
+ model
139
+ ? {
140
+ name: target.name,
141
+ parent_id,
142
+ url: is_project ? `/project/` + target.controller : '',
143
+ model_id: model ? model.id : 0,
144
+ key: is_project
145
+ ? ''
146
+ : model && model.belongs
147
+ ? `${model.belongs}/${model.model}`
148
+ : '',
149
+ }
150
+ : null,
151
+ ].filter(Boolean)
143
152
  }
144
153
  const sortList = list.map((item) => {
145
154
  const sort = routesList.find((r) => r.name === item.name)
@@ -1,6 +1,7 @@
1
1
  const { getConfig, lodash } = require('q-koa')
2
2
  const formatPostFunction = (str) => `eval(${str})`
3
3
  const nodeVm = require('vm')
4
+ const axios = require('axios')
4
5
 
5
6
  exports.initData = async ({ includes, excludes, app, ctx }) => {
6
7
  const appConfig = getConfig(app)
@@ -69,7 +69,7 @@ module.exports = class Singleton {
69
69
  const Print = new yly.Print(RpcClient)
70
70
  const res = await Print.index(this.config.machine_code, order_id, content)
71
71
 
72
- if (res.code !== '0') {
72
+ if (res && res.error_description !== 'success') {
73
73
  throw new Error(res.error_description)
74
74
  }
75
75
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "8.9.5",
3
+ "version": "9.0.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {