定制项目打包接口完成

This commit is contained in:
aixianling
2022-07-07 17:43:04 +08:00
parent 7dd22f51fe
commit 091deb59ef
2 changed files with 52 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
const dbUtils = require("../../utils/dbUitls");
module.exports = {
action: "/node/custom/cancelZip",
method: "post",
execute: (request, response) => {
let id = request.query?.id, sql = `update node_custom_config set zipTime=null where id='${id}'`
dbUtils.query(sql).then(() => {
response.send({code: 0, data: "取消成功!"})
}).catch(err => {
console.log(err)
response.send({code: 1, err: err.sqlMessage})
})
}
}

38
src/rest/custom/getZip.js Normal file
View File

@@ -0,0 +1,38 @@
const db = require("../../utils/dbUitls");
const execute = require("../../tools/exec")
const dayjs = require("dayjs")
const fse = require("fs-extra");
module.exports = {
action: "/node/custom/getZip",
method: "post",
execute: (request, response) => {
let {id} = request.query, uniCon = `id='${id}'`.db.query(`select * from node_custom_config where id='${id}'`).then(res => {
let info = res?.[0], sql
if (info?.id) {
sql = `update node_custom_config set download=null,error=null,zipTime='${dayjs().format("YYYY-MM-DD HH:mm:ss")}' where ${uniCon}`
db.query(sql).then(() => setTimeout(() => {
response.send({code: 0})
}, 2000))
const buildPath = {
web: 'base-web',
wxwork: 'base-wxcp',
mp: ''
}[info.type] || {}
const path = `/home/deploy/node-service/${buildPath}`,
dest = `/home/deploy/node-service/customZips/${id}/`
execute(`cd ${path}&&npm run apps&&node bin/pages.js ${id}&&npm run build`)
.then(() => fse.emptyDir(dest))
.then(() => execute(`/root/node-service/move.sh ${info.type} ${path} ${dest}`))
.then(() => {
return db.query(`update node_custom_config set download='${dayjs().format("YYYY-MM-DD HH:mm:ss")}',error='' where ${uniCon}`)
}).catch(err => {
console.log(err)
return db.query(`update node_custom_config set error='${err}',zipTime=null where ${uniCon}`)
})
} else return response.send({code: 1, err: "无法找到定制项目信息"})
}).catch(err => {
console.log(err)
response.send({code: 1, err: err.sqlMessage})
})
}
}