q-koa 7.7.6 → 7.7.7
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 +13 -9
- package/core/file/plugins/common/controller.js +8 -4
- package/core/file/plugins/model/controller.js +7 -4
- package/core/file/plugins/model/service.js +11 -11
- package/core/file/plugins/system/controller.js +4 -2
- package/core/file/plugins/weixin/service.js +3 -2
- package/core/file/services/toutiao.js +2 -2
- package/core/file/services/weixinMP.js +2 -1
- package/core/restc/lib/index.js +4 -1
- package/package.json +1 -1
package/core/app.js
CHANGED
|
@@ -3,6 +3,7 @@ const Router = require('koa-router')
|
|
|
3
3
|
const _ = require('lodash')
|
|
4
4
|
const path = require('path')
|
|
5
5
|
const fs = require('fs')
|
|
6
|
+
const fsPromise = require('fs/promises')
|
|
6
7
|
const Sequelize = require('sequelize')
|
|
7
8
|
const moment = require('moment')
|
|
8
9
|
const { EventEmitter } = require('events')
|
|
@@ -261,7 +262,7 @@ class APP {
|
|
|
261
262
|
appName: appName,
|
|
262
263
|
})
|
|
263
264
|
} else {
|
|
264
|
-
|
|
265
|
+
await fsPromise.writeFile(
|
|
265
266
|
`${rootDirectory}/${APP_DIR}/${appName}/${PLUGINS_DIR}/model/service.js`,
|
|
266
267
|
''
|
|
267
268
|
)
|
|
@@ -294,7 +295,7 @@ class APP {
|
|
|
294
295
|
}
|
|
295
296
|
|
|
296
297
|
async initApp() {
|
|
297
|
-
let dirList =
|
|
298
|
+
let dirList = await fsPromise.readdir(
|
|
298
299
|
path.resolve(__dirname, `${rootDirectory}/${APP_DIR}`)
|
|
299
300
|
)
|
|
300
301
|
dirList = dirList.filter((item) => this.config.includes.includes(item))
|
|
@@ -428,11 +429,13 @@ class APP {
|
|
|
428
429
|
`${rootDirectory}/${APP_DIR}/${appName}/task`
|
|
429
430
|
)
|
|
430
431
|
const publicExist = fs.existsSync(taskDir)
|
|
431
|
-
if (!publicExist)
|
|
432
|
-
|
|
432
|
+
if (!publicExist) await fsPromise.mkdir(taskDir)
|
|
433
|
+
const list = await fsPromise.readdir(taskDir)
|
|
434
|
+
list.forEach((folder) => {
|
|
433
435
|
const isFolder = fs.lstatSync(path.resolve(taskDir, folder)).isDirectory()
|
|
434
436
|
if (isFolder) {
|
|
435
|
-
|
|
437
|
+
const folderDir = await fsPromise.readdir(path.resolve(taskDir, folder))
|
|
438
|
+
folderDir.forEach((filename) => {
|
|
436
439
|
if (filename === 'index.js') {
|
|
437
440
|
const task = require(path.resolve(
|
|
438
441
|
__dirname,
|
|
@@ -456,14 +459,15 @@ class APP {
|
|
|
456
459
|
`${rootDirectory}/${APP_DIR}/${appName}/${PLUGINS_DIR}`
|
|
457
460
|
)
|
|
458
461
|
const publicExist = fs.existsSync(pluginDir)
|
|
459
|
-
if (!publicExist)
|
|
460
|
-
|
|
461
|
-
|
|
462
|
+
if (!publicExist) await fsPromise.mkdir(pluginDir)
|
|
463
|
+
const pluginDirResult = await fsPromise.readdir(pluginDir)
|
|
464
|
+
pluginDirResult.forEach((folder) => {
|
|
462
465
|
const isFolder = fs
|
|
463
466
|
.lstatSync(path.resolve(pluginDir, folder))
|
|
464
467
|
.isDirectory()
|
|
465
468
|
if (isFolder) {
|
|
466
|
-
|
|
469
|
+
const folderResult = await fsPromise.readdir(path.resolve(pluginDir, folder))
|
|
470
|
+
folderResult.forEach((filename) => {
|
|
467
471
|
const extname = path.extname(filename)
|
|
468
472
|
if (extname === '.js') {
|
|
469
473
|
const n = path.basename(filename, extname)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
|
+
const fsPromise = require('fs/promises')
|
|
2
3
|
const path = require('path')
|
|
3
4
|
const crypto = require('crypto')
|
|
4
5
|
const { Random, lodash, getAppByCtx, getConfig } = require('q-koa')
|
|
@@ -36,7 +37,7 @@ exports.upload = async (ctx) => {
|
|
|
36
37
|
|
|
37
38
|
const { site_host } = await appConfig.getObject('base')
|
|
38
39
|
|
|
39
|
-
const reader =
|
|
40
|
+
const reader = await fsPromise.readFile(file.path)
|
|
40
41
|
|
|
41
42
|
const fsHash = crypto.createHash('md5')
|
|
42
43
|
fsHash.update(reader)
|
|
@@ -66,7 +67,7 @@ exports.upload = async (ctx) => {
|
|
|
66
67
|
)
|
|
67
68
|
if (isExists) return ctx.SUCCESS(responseData)
|
|
68
69
|
|
|
69
|
-
|
|
70
|
+
await fsPromise.writeFile(targetPath, reader)
|
|
70
71
|
return ctx.SUCCESS(responseData)
|
|
71
72
|
}
|
|
72
73
|
|
|
@@ -220,7 +221,7 @@ exports.swagger = async (ctx) => {
|
|
|
220
221
|
`${process.cwd()}/app/${appName}/plugins`
|
|
221
222
|
)
|
|
222
223
|
const apis = []
|
|
223
|
-
const pathList =
|
|
224
|
+
const pathList = await fsPromise.readdir(filePath)
|
|
224
225
|
for (let i = 0; i < pathList.length; i++) {
|
|
225
226
|
const folder = pathList[i]
|
|
226
227
|
const isFolder = fs.lstatSync(path.resolve(filePath, folder)).isDirectory()
|
|
@@ -240,7 +241,10 @@ exports.swagger = async (ctx) => {
|
|
|
240
241
|
const controllerFilePath = path.resolve(filePath, folder, 'controller.js')
|
|
241
242
|
const isControllerExist = fs.existsSync(controllerFilePath)
|
|
242
243
|
if (isControllerExist) {
|
|
243
|
-
const controllerFile =
|
|
244
|
+
const controllerFile = await fsPromise.readFile(
|
|
245
|
+
controllerFilePath,
|
|
246
|
+
'utf-8'
|
|
247
|
+
)
|
|
244
248
|
const annotations = controllerFile.match(annotationsReg)
|
|
245
249
|
|
|
246
250
|
if (annotations) {
|
|
@@ -2,6 +2,7 @@ const { getAppByCtx, lodash } = require('q-koa')
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs')
|
|
4
4
|
const path = require('path')
|
|
5
|
+
const fsPromise = require('fs/promises')
|
|
5
6
|
|
|
6
7
|
exports.getModel = async (ctx) => {
|
|
7
8
|
const { app, appName } = getAppByCtx(ctx)
|
|
@@ -19,7 +20,7 @@ exports.getModel = async (ctx) => {
|
|
|
19
20
|
)
|
|
20
21
|
)
|
|
21
22
|
if (!existFile) return ctx.SUCCESS('')
|
|
22
|
-
const file =
|
|
23
|
+
const file = await fsPromise.readFile(
|
|
23
24
|
path.resolve(
|
|
24
25
|
__dirname,
|
|
25
26
|
`${process.cwd()}/app/${appName}/plugins/${model}/${option}.js`
|
|
@@ -54,7 +55,7 @@ exports.createFile = async (ctx) => {
|
|
|
54
55
|
`${process.cwd()}/app/${appName}/plugins/${plugin}`
|
|
55
56
|
)
|
|
56
57
|
const exist = fs.existsSync(pluginDirPath)
|
|
57
|
-
if (!exist)
|
|
58
|
+
if (!exist) await fsPromise.mkdir(pluginDirPath)
|
|
58
59
|
const list = ['config', 'model', 'controller']
|
|
59
60
|
|
|
60
61
|
for (let i = 0; i < list.length; i++) {
|
|
@@ -62,8 +63,10 @@ exports.createFile = async (ctx) => {
|
|
|
62
63
|
if (!obj[type]) {
|
|
63
64
|
continue
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
+
await fsPromise.writeFile(
|
|
67
|
+
path.resolve(pluginDirPath, `${type}.js`),
|
|
68
|
+
obj[type]
|
|
69
|
+
)
|
|
66
70
|
}
|
|
67
|
-
// fs.writeFileSync(path.resolve(pluginDirPath, 'config.js'), desc)
|
|
68
71
|
ctx.SUCCESS('ok')
|
|
69
72
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
2
|
const path = require('path')
|
|
3
|
-
|
|
3
|
+
const fsPromise = require('fs/promises')
|
|
4
4
|
exports.loadModel = async ({ app, appName }) => {
|
|
5
|
-
const data =
|
|
5
|
+
const data = await fsPromise.readdir(
|
|
6
6
|
path.resolve(__dirname, `${process.cwd()}/app/${appName}/plugins`)
|
|
7
7
|
)
|
|
8
8
|
|
|
9
|
-
const modelList = await app.model.model.findAll({ raw: true })
|
|
9
|
+
// const modelList = await app.model.model.findAll({ raw: true })
|
|
10
10
|
|
|
11
11
|
await Promise.all(
|
|
12
12
|
['model', 'model_attributes'].map((item) =>
|
|
@@ -34,32 +34,32 @@ exports.loadModel = async ({ app, appName }) => {
|
|
|
34
34
|
__dirname,
|
|
35
35
|
`../${result[i]}/config.js`
|
|
36
36
|
)
|
|
37
|
-
|
|
38
37
|
const modelExist = fs.existsSync(filePath)
|
|
39
38
|
const defaultModelExist = fs.existsSync(defaultFilePath)
|
|
40
39
|
const configExist = fs.existsSync(configPath)
|
|
41
40
|
if (configExist) {
|
|
42
|
-
const config =
|
|
41
|
+
const config = (await fsPromise.readFile(configPath, 'utf-8'))
|
|
43
42
|
? require(configPath)
|
|
44
43
|
: require(defaultConfigPath)
|
|
45
44
|
|
|
46
45
|
const modelFile =
|
|
47
46
|
defaultModelExist || modelExist
|
|
48
|
-
?
|
|
49
|
-
?
|
|
50
|
-
:
|
|
47
|
+
? (await fsPromise.readFile(filePath, 'utf-8'))
|
|
48
|
+
? await fsPromise.readFile(filePath, 'utf-8')
|
|
49
|
+
: await fsPromise.readFile(defaultFilePath, 'utf-8')
|
|
51
50
|
: null
|
|
52
51
|
|
|
53
52
|
const model = modelFile
|
|
54
|
-
?
|
|
53
|
+
? (await fsPromise.readFile(filePath, 'utf-8'))
|
|
55
54
|
? require(filePath)
|
|
56
55
|
: require(defaultFilePath)
|
|
57
56
|
: {}
|
|
58
57
|
const attributes = modelFile ? modelFile.match(/exports.(.*)=/g) : []
|
|
59
58
|
const types = modelFile ? modelFile.match(/Sequelize.(.*),\n/g) : {}
|
|
60
59
|
|
|
61
|
-
const ori_target = modelList.find((m) => m.model === result[i])
|
|
62
|
-
const id = ori_target ? ori_target.id : null
|
|
60
|
+
// const ori_target = modelList.find((m) => m.model === result[i])
|
|
61
|
+
// const id = ori_target ? ori_target.id : null
|
|
62
|
+
const id = i + 1
|
|
63
63
|
const obj = {
|
|
64
64
|
id,
|
|
65
65
|
model: result[i],
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
2
|
const path = require('path')
|
|
3
|
+
const fsPromise = require('fs/promises')
|
|
3
4
|
const { VM } = require('vm2')
|
|
4
5
|
const axios = require('axios')
|
|
5
6
|
const cheerio = require('cheerio')
|
|
@@ -57,7 +58,8 @@ exports.showTables = async (ctx) => {
|
|
|
57
58
|
`${process.cwd()}/app/${appName}/plugins`
|
|
58
59
|
)
|
|
59
60
|
let aliasModelList = []
|
|
60
|
-
|
|
61
|
+
const allList = await fsPromise.readdir(pluginDir)
|
|
62
|
+
allList.forEach((folder) => {
|
|
61
63
|
const isFolder = fs.lstatSync(path.resolve(pluginDir, folder)).isDirectory()
|
|
62
64
|
const hasConfig = fs.existsSync(
|
|
63
65
|
path.resolve(
|
|
@@ -249,7 +251,7 @@ exports.getImage = async (ctx) => {
|
|
|
249
251
|
__dirname,
|
|
250
252
|
`${process.cwd()}/public/upload`
|
|
251
253
|
)}`
|
|
252
|
-
const files =
|
|
254
|
+
const files = await fsPromise.readdir(targetDir)
|
|
253
255
|
const images = files.filter((file) =>
|
|
254
256
|
/\w(\.gif|\.jpeg|\.png|\.jpg|\.bmp)/i.test(file)
|
|
255
257
|
)
|
|
@@ -2,6 +2,7 @@ const { getAppByCtx, getConfig } = require('q-koa')
|
|
|
2
2
|
const { Pay } = require('@sigodenjs/wechatpay')
|
|
3
3
|
const fs = require('fs')
|
|
4
4
|
const path = require('path')
|
|
5
|
+
const fsPromise = require('fs/promises')
|
|
5
6
|
|
|
6
7
|
exports.refund = async ({
|
|
7
8
|
ctx,
|
|
@@ -21,7 +22,7 @@ exports.refund = async ({
|
|
|
21
22
|
appId: appId,
|
|
22
23
|
mchId: mchId,
|
|
23
24
|
key: key, // 微信商户平台API密钥,
|
|
24
|
-
pfx:
|
|
25
|
+
pfx: await fsPromise.readFile(
|
|
25
26
|
path.resolve(
|
|
26
27
|
__dirname,
|
|
27
28
|
`${process.cwd()}/app/${appName}/plugins/weixin/apiclient_cert.p12`
|
|
@@ -71,7 +72,7 @@ exports.cash = async ({ ctx, id, user_id, number }) => {
|
|
|
71
72
|
appId: appId,
|
|
72
73
|
mchId: mchId,
|
|
73
74
|
key: key, // 微信商户平台API密钥,
|
|
74
|
-
pfx:
|
|
75
|
+
pfx: await fsPromise.readFile(
|
|
75
76
|
path.resolve(
|
|
76
77
|
__dirname,
|
|
77
78
|
`${process.cwd()}/app/${appName}/plugins/weixin/apiclient_cert.p12`
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const util = require('util')
|
|
2
2
|
const axios = require('axios')
|
|
3
|
-
|
|
3
|
+
const fsPromise = require('fs/promises')
|
|
4
4
|
const { lodash } = require('q-koa')
|
|
5
5
|
const getAccessTokenUrl =
|
|
6
6
|
'https://developer.toutiao.com/api/apps/token?grant_type=%s&appid=%s&secret=%s'
|
|
@@ -88,7 +88,7 @@ module.exports = class Singleton {
|
|
|
88
88
|
}
|
|
89
89
|
throw new Error(bufferResult.errmsg)
|
|
90
90
|
}
|
|
91
|
-
await
|
|
91
|
+
await fsPromise.writeFile(
|
|
92
92
|
`${this.config.targetPath}/${creatuuid}.png`,
|
|
93
93
|
bufferResult
|
|
94
94
|
)
|
|
@@ -31,6 +31,7 @@ const addOrderUrl =
|
|
|
31
31
|
|
|
32
32
|
const path = require('path')
|
|
33
33
|
const fs = require('fs')
|
|
34
|
+
const fsPromise = require('fs/promises')
|
|
34
35
|
const LRU = require('lru-cache')
|
|
35
36
|
const request = require('request')
|
|
36
37
|
const cache = new LRU({
|
|
@@ -313,7 +314,7 @@ module.exports = class Singleton {
|
|
|
313
314
|
}
|
|
314
315
|
throw new Error(bufferResult.errmsg)
|
|
315
316
|
}
|
|
316
|
-
await
|
|
317
|
+
await fsPromise.writeFile(
|
|
317
318
|
`${this.config.targetPath}/${creatuuid}.png`,
|
|
318
319
|
bufferResult
|
|
319
320
|
)
|
package/core/restc/lib/index.js
CHANGED
|
@@ -4,7 +4,10 @@ const fs = require('fs')
|
|
|
4
4
|
const path = require('path')
|
|
5
5
|
const Gateway = require('./utils/gateway.js')
|
|
6
6
|
|
|
7
|
-
const content = fs.readFileSync(
|
|
7
|
+
const content = fs.readFileSync(
|
|
8
|
+
path.join(__dirname, '../faas/index.html'),
|
|
9
|
+
'utf-8'
|
|
10
|
+
)
|
|
8
11
|
|
|
9
12
|
const cache = new WeakMap()
|
|
10
13
|
|