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