From cbba345806a3a5ab438170137322495dbe79e42f Mon Sep 17 00:00:00 2001 From: aixianling Date: Thu, 19 May 2022 11:09:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8B=E8=BD=BD=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rest/wechat/download.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/rest/wechat/download.js 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: "无法找到小程序信息"}) + } +}