优化打包下载
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
},
|
||||
"author": "kubbo",
|
||||
"dependencies": {
|
||||
"archiver": "^5.3.0",
|
||||
"dayjs": "^1.11.0",
|
||||
"express": "^4.17.3",
|
||||
"fs-extra": "^10.0.1",
|
||||
|
||||
@@ -1,25 +1,17 @@
|
||||
const archiver = require("archiver")
|
||||
const fse = require("fs-extra");
|
||||
const fs = require("fs");
|
||||
const execute = require("../../tools/exec");
|
||||
module.exports = {
|
||||
action: "/node/wxmp/download",
|
||||
method: "post",
|
||||
execute: (request, response) => {
|
||||
let appid = request.query?.appid
|
||||
if (appid) {
|
||||
let path = `../wxmpZips/${appid}/`, zipPath = `../wxmpZips/${appid}.zip`
|
||||
let path = `/root/node-service/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(() => {
|
||||
execute(`cd /root/node-service/wxmpZips&&zip -r ${appid}.zip ${path}`).then(() => {
|
||||
console.log('压缩完成!')
|
||||
setTimeout(() => {
|
||||
response.download(zipPath)
|
||||
|
||||
Reference in New Issue
Block a user