Files
dvcp-node-service/src/rest/wechat/download.js
2022-06-30 10:13:47 +08:00

27 lines
985 B
JavaScript

const fse = require("fs-extra");
const execute = require("../../tools/exec");
module.exports = {
action: "/node/wxmp/download",
method: "post",
execute: (request, response) => {
let {pid, appid: aid} = request.query, appid = [aid, pid].join("_")
if (appid) {
let path = `/home/deploy/wxmpZips/${appid}/`, zipPath = `/home/deploy/wxmpZips/${appid}.zip`
fse.removeSync(zipPath)
fse.pathExists(path, (err, exists) => {
console.log(`${path}=========>${exists}`)
if (exists) {
execute(`cd ${path}&&zip -r ${appid}.zip .`)
.then(() => execute(`cd ${path}&&mv ${appid}.zip /home/deploy/wxmpZips`))
.then(() => {
console.log('压缩完成!')
setTimeout(() => {
response.download(zipPath)
}, 1000)
})
} else response.send({code: 1, err: "没有打包文件!"})
})
} else response.send({code: 1, err: "无法找到小程序信息"})
}
}