添加下载接口

This commit is contained in:
aixianling
2022-05-19 11:09:22 +08:00
parent 7c21a10862
commit cbba345806

View 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: "无法找到小程序信息"})
}
}