diff --git a/src/websocket/custom/getZip.js b/src/websocket/custom/getZip.js index e70c57c..13a0e7e 100644 --- a/src/websocket/custom/getZip.js +++ b/src/websocket/custom/getZip.js @@ -17,23 +17,23 @@ const handleZip = (id, ws) => { }, 6000) } - set(progress, remark) { + set(progress, id) { if (this.timer) clearInterval(this.timer) this.count = progress - sendMessage({code: 0, progress: this.count, remark}) + sendMessage({code: 0, progress: this.count, id}) this.timer = setInterval(() => { - sendMessage({code: 0, progress: ++this.count, remark}) + sendMessage({code: 0, progress: ++this.count, id}) }, 4000) } stop(row) { if (this.timer) clearInterval(this.timer) - sendMessage({code: 1, row}) + sendMessage({code: 1, row, id: row.id}) } finish(row) { if (this.timer) clearInterval(this.timer) - sendMessage({code: 0, progress: 100, row}) + sendMessage({code: 0, progress: 100, row, id: row.id}) } } @@ -47,23 +47,23 @@ const handleZip = (id, ws) => { let path = `../${buildPath}`, {dist} = info dist = dist || `../zips/${info.name}v${info.version || "1.0.0"}` Promise.all([db.query(`update node_custom_config set download=null,error=null,zipTime='${dayjs().format("YYYY-MM-DD HH:mm:ss")}' where ${uniCon}`), execute(`./shell/update.sh ${info.name} ${path}`, signal)]) - .then(cmd => progress.set(30, cmd)) - .then(() => execute(`cd ${path}&&npm run apps&&node bin/pages.js ${id}&&npm run build`, signal)) - .then(cmd => progress.set(70, cmd)) - .then(() => fse.emptyDir(dist)) - .then(() => execute(`./shell/move.sh ${info.type} ${path} ${dist}`, signal)) - .then(cmd => progress.set(90, cmd)) - .then(() => db.query(`update node_custom_config set download='${dayjs().format("YYYY-MM-DD HH:mm:ss")}',error='' where ${uniCon}`)) - .then(() => db.detail({table: "node_custom_config", id})) - .then(row => progress.finish(row)) - .catch(err => { - console.log(err) - const msg = `执行失败:${err.cmd}` - return db.query(`update node_custom_config set error='${msg}',zipTime=null where ${uniCon}`) + .then(cmd => progress.set(30, info?.id)) + .then(() => execute(`cd ${path}&&npm run apps&&node bin/pages.js ${id}&&npm run build`, signal)) + .then(cmd => progress.set(70, info?.id)) + .then(() => fse.emptyDir(dist)) + .then(() => execute(`./shell/move.sh ${info.type} ${path} ${dist}`, signal)) + .then(cmd => progress.set(90, info?.id)) + .then(() => db.query(`update node_custom_config set download='${dayjs().format("YYYY-MM-DD HH:mm:ss")}',error='' where ${uniCon}`)) .then(() => db.detail({table: "node_custom_config", id})) - .then(row => progress.stop(row)) - .catch(() => 0) - }) + .then(row => progress.finish(row)) + .catch(err => { + console.log(err) + const msg = `执行失败:${err.cmd}` + return db.query(`update node_custom_config set error='${msg}',zipTime=null where ${uniCon}`) + .then(() => db.detail({table: "node_custom_config", id})) + .then(row => progress.stop(row)) + .catch(() => 0) + }) } }).catch(err => { console.log(err)