diff --git a/src/rest/wechat/download.js b/src/rest/wechat/download.js new file mode 100644 index 0000000..ac8626e --- /dev/null +++ b/src/rest/wechat/download.js @@ -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: "无法找到小程序信息"}) + } +}