Files
dvcp-node-service/src/rest/aicode/getCode.js
2023-02-13 10:42:25 +08:00

35 lines
1.2 KiB
JavaScript

const dbUtils = require("../../utils/dbUitls");
const fse = require("fs-extra");
const execute = require("../../tools/exec");
const generate = require("../../tools/generate");
module.exports = {
action: "/node/aicode/getCode",
method: "post",
execute: (request, response) => {
let id = request.query?.id, sql = `select * from node_aicode where id='${id}'`
dbUtils.query(sql).then(res => {
let info = res?.[0]
if (info?.id) {
let path = `./aicode/${info.id}`, zipPath = `${path}/${info.id}.zip`
generate(info, path).then(() => {
fse.pathExists(path, (err, exists) => {
console.log(`${path}=========>${exists}`)
if (exists) {
execute(`cd ${path}&&zip -r ${info.id}.zip .`)
.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})
})
}
}