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