2022-07-04 14:43:22 +08:00
|
|
|
const dbUtils = require("../../utils/dbUitls");
|
|
|
|
|
const fse = require("fs-extra");
|
|
|
|
|
const execute = require("../../tools/exec");
|
|
|
|
|
module.exports = {
|
|
|
|
|
action: "/node/custom/download",
|
|
|
|
|
method: "post",
|
|
|
|
|
execute: (request, response) => {
|
|
|
|
|
let id = request.query?.id
|
|
|
|
|
dbUtils.detail({table: 'node_custom_config', id}).then(info => {
|
|
|
|
|
if (info?.id) {
|
2022-12-28 16:05:27 +08:00
|
|
|
let path = `${info.dist || `../zips/${id}`}`, zipPath = `../zips/${info.id}.zip`
|
2022-07-04 14:43:22 +08:00
|
|
|
fse.removeSync(zipPath)
|
|
|
|
|
fse.pathExists(path, (err, exists) => {
|
|
|
|
|
console.log(`${path}=========>${exists}`)
|
|
|
|
|
if (exists) {
|
|
|
|
|
execute(`cd ${path}&&zip -r ${info.id}.zip .`)
|
2022-12-28 16:05:27 +08:00
|
|
|
.then(() => execute(`cd ${path}&&mv ${info.id}.zip ../zips`))
|
2022-07-04 14:43:22 +08:00
|
|
|
.then(() => {
|
|
|
|
|
console.log('压缩完成!')
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
response.download(zipPath)
|
|
|
|
|
}, 1000)
|
|
|
|
|
})
|
|
|
|
|
} else response.send({code: 1, err: "没有打包文件!"})
|
|
|
|
|
})
|
|
|
|
|
} else response.send({code: 1, err: "无法找到项目信息"})
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
console.log(err)
|
|
|
|
|
response.send({code: 1, err: err.sqlMessage})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|