Files
dvcp-node-service/src/rest/wechat/download.js
2022-05-19 11:09:22 +08:00

33 lines
1.0 KiB
JavaScript

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