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) { let path = `${info.dist || `../zips/${id}`}`, zipPath = `../zips/${info.id}.zip` fse.removeSync(zipPath) fse.pathExists(path, (err, exists) => { console.log(`${path}=========>${exists}`) if (exists) { execute(`cd ${path}&&zip -r ${info.id}.zip .`) .then(() => execute(`cd ${path}&&mv ${info.id}.zip ../zips`)) .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}) }) } }