q-koa 8.7.2 → 8.8.2
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
|
@@ -146,6 +146,9 @@ class APP {
|
|
|
146
146
|
return ctx.ERROR('error')
|
|
147
147
|
}
|
|
148
148
|
const appName = url.split('/')[1]
|
|
149
|
+
if (!appName || !(ctx.app[appName] && ctx.app[appName].appConfig)) {
|
|
150
|
+
return ctx.ERROR('error')
|
|
151
|
+
}
|
|
149
152
|
const { secret, whiteList, _whiteList, tokenKey, expiresIn } =
|
|
150
153
|
ctx.app[appName] && ctx.app[appName].appConfig
|
|
151
154
|
? ctx.app[appName].appConfig.jwt
|
|
@@ -406,19 +406,64 @@ exports.verify = async (ctx) => {
|
|
|
406
406
|
exports.express = async (ctx) => {
|
|
407
407
|
const { app } = getAppByCtx(ctx)
|
|
408
408
|
const appConfig = getConfig(app)
|
|
409
|
-
const { app_code } = await appConfig.getObject('express')
|
|
409
|
+
const { app_code, express_mobile } = await appConfig.getObject('express')
|
|
410
410
|
|
|
411
|
-
const
|
|
412
|
-
app_code,
|
|
413
|
-
})
|
|
411
|
+
const { express_number: _express_number } = ctx.request.body
|
|
414
412
|
|
|
415
|
-
const
|
|
413
|
+
const express_number = _express_number.replace(/\t/, '').trim()
|
|
416
414
|
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
415
|
+
const lastFour = express_mobile
|
|
416
|
+
.split('')
|
|
417
|
+
.slice(express_mobile.length - 4, express_mobile.length)
|
|
418
|
+
.join('')
|
|
420
419
|
|
|
421
|
-
|
|
420
|
+
let history = null
|
|
421
|
+
if (app.model.express_record) {
|
|
422
|
+
history = await app.model.express_record.findOne({
|
|
423
|
+
where: {
|
|
424
|
+
express_number,
|
|
425
|
+
},
|
|
426
|
+
})
|
|
427
|
+
if (history) {
|
|
428
|
+
const diffNoLong = moment().diff(moment(history.updated_at), 'hours') < 1
|
|
429
|
+
const isTooLong =
|
|
430
|
+
moment().diff(moment(history.result.updateTime), 'days') > 30
|
|
431
|
+
|
|
432
|
+
if (diffNoLong || isTooLong) {
|
|
433
|
+
return ctx.SUCCESS(history.result)
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
try {
|
|
439
|
+
const express = new Express({
|
|
440
|
+
app_code,
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
const result = await express.send({
|
|
444
|
+
no: express_number.startsWith('SF')
|
|
445
|
+
? `${express_number}:${lastFour}`
|
|
446
|
+
: express_number,
|
|
447
|
+
})
|
|
448
|
+
|
|
449
|
+
if (app.model.express_record) {
|
|
450
|
+
if (!history) {
|
|
451
|
+
app.model.express_record.upsert({
|
|
452
|
+
express_number,
|
|
453
|
+
result,
|
|
454
|
+
})
|
|
455
|
+
} else {
|
|
456
|
+
app.model.express_record.upsert({
|
|
457
|
+
id: history.id,
|
|
458
|
+
result,
|
|
459
|
+
})
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
ctx.SUCCESS(result)
|
|
464
|
+
} catch (e) {
|
|
465
|
+
return ctx.SUCCESS(null)
|
|
466
|
+
}
|
|
422
467
|
}
|
|
423
468
|
|
|
424
469
|
exports.urlToOss = async (ctx) => {
|