添加下载接口
This commit is contained in:
32
src/rest/wechat/download.js
Normal file
32
src/rest/wechat/download.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
const archiver = require("archiver")
|
||||||
|
const fse = require("fs-extra");
|
||||||
|
const fs = require("fs");
|
||||||
|
module.exports = {
|
||||||
|
action: "/node/autodeploy/download",
|
||||||
|
method: "post",
|
||||||
|
execute: (request, response) => {
|
||||||
|
let appid = request.query?.appid
|
||||||
|
if (appid) {
|
||||||
|
let path = `../wxmpZips/${appid}/`, zipPath = `./wxmpZips/${appid}.zip`
|
||||||
|
fse.removeSync(zipPath)
|
||||||
|
fse.pathExists(path, (err, exists) => {
|
||||||
|
console.log(`${path}=========>${exists}`)
|
||||||
|
if (exists) {
|
||||||
|
let output = fs.createWriteStream(zipPath),
|
||||||
|
arc = archiver('zip')
|
||||||
|
arc.on('error', err => {
|
||||||
|
response.send({code: 1, err})
|
||||||
|
})
|
||||||
|
arc.pipe(output)
|
||||||
|
arc.directory(path, false)
|
||||||
|
arc.finalize().then(() => {
|
||||||
|
console.log('压缩完成!')
|
||||||
|
setTimeout(() => {
|
||||||
|
response.download(zipPath)
|
||||||
|
}, 1000)
|
||||||
|
})
|
||||||
|
} else response.send({code: 1, err: "没有打包文件!"})
|
||||||
|
})
|
||||||
|
} else response.send({code: 1, err: "无法找到小程序信息"})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user