q-koa 8.5.0 → 8.5.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.
@@ -104,7 +104,9 @@ exports.showTables = async (ctx) => {
104
104
  const defaultConfigPath = path.resolve(__dirname, `../${_model}/config.js`)
105
105
  const defaultConfigExist = fs.existsSync(defaultConfigPath)
106
106
  const target =
107
- Object.keys(app.config[_model]).length === 0 && defaultConfigExist
107
+ app.config[_model] &&
108
+ Object.keys(app.config[_model]).length === 0 &&
109
+ defaultConfigExist
108
110
  ? require(defaultConfigPath)
109
111
  : app.config[_model]
110
112
  // const target = Object.keys(app.config[model])
@@ -112,6 +112,7 @@ exports.cash = async ({
112
112
  if (result.err_code_des) throw new Error(result.err_code_des)
113
113
  return result
114
114
  }
115
+
115
116
  exports.qr_code = async ({
116
117
  app,
117
118
  page,
@@ -168,17 +169,35 @@ exports.qr_code = async ({
168
169
  const fileName = `${
169
170
  String(new Date().getTime()).split('').reverse().join('') + Math.random()
170
171
  }.png`
171
- const result = await client.put(fileName, buffer)
172
- if (result.res && result.res.status === 200) {
173
- if (oss_host && cdn_host) {
174
- const url = result.url.replace(oss_host, cdn_host)
172
+
173
+ const handelResult = (result) => {
174
+ if (result && result.res && result.res.status === 200) {
175
+ if (oss_host && cdn_host) {
176
+ const url = result.url.replace(oss_host, cdn_host)
177
+ return url
178
+ } else {
179
+ return result.url
180
+ }
181
+ } else {
182
+ return null
183
+ }
184
+ }
185
+ try {
186
+ const result = await client.put(fileName, buffer)
187
+ const url = handelResult(result)
188
+ if (url) {
175
189
  return url
176
190
  } else {
177
- const url = result.url
191
+ throw new Error(`发生错误,请重试`)
192
+ }
193
+ } catch (e) {
194
+ const result = await client.put(fileName, buffer)
195
+ const url = handelResult(result)
196
+ if (url) {
178
197
  return url
198
+ } else {
199
+ throw new Error(`发生错误,请重试`)
179
200
  }
180
- } else {
181
- throw new Error(result.res.statusMessage)
182
201
  }
183
202
  }
184
203
  }
@@ -15,7 +15,7 @@ exports.getList = (config) => (type) => {
15
15
  return list
16
16
  }
17
17
 
18
- exports.getObject = (config) => (type) => {
18
+ exports.getObject = (config, app) => async (type) => {
19
19
  if (app) {
20
20
  const applicationList = await app.cache.get('application')
21
21
  if (
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "8.5.0",
3
+ "version": "8.5.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {