From 02001e78c25475c1848d26ecc1592b2561ad728f Mon Sep 17 00:00:00 2001 From: aixianling Date: Wed, 18 Jan 2023 14:06:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9D=80=E6=AD=BB=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B=E7=9A=84=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tools/childProcess.js | 8 ++++++++ src/websocket/custom/getZip.js | 11 +++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/tools/childProcess.js b/src/tools/childProcess.js index a481f4c..6770c0b 100644 --- a/src/tools/childProcess.js +++ b/src/tools/childProcess.js @@ -21,6 +21,14 @@ class Process { resolve() } else reject(err) }) + this.pid.on('exit', (code, err) => { + if (code == 0 && !err) { + resolve() + } else reject(err) + }) + this.pid.stdout.on('data', data => { + console.log(data) + }) }) } } diff --git a/src/websocket/custom/getZip.js b/src/websocket/custom/getZip.js index a0e4633..7cbc3c9 100644 --- a/src/websocket/custom/getZip.js +++ b/src/websocket/custom/getZip.js @@ -3,7 +3,7 @@ const execute = require("../../tools/exec") const process = require("../../tools/childProcess") const dayjs = require("dayjs") const fse = require("fs-extra"); - +let pid const handleZip = (id, ws) => { const uniCon = `id='${id}'` const sendMessage = data => ws.send(JSON.stringify(data)) @@ -15,7 +15,7 @@ const handleZip = (id, ws) => { wxwork: 'base-wxcp', mp: 'dvcp_v2_wxmp' }[info.type] || {} - let path = `../${buildPath}`, {dist} = info, pid + 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}`), @@ -52,8 +52,11 @@ module.exports = { if (res?.data) { const data = JSON.parse(res.data) if (data.cid == id) { - - } else if (id == data.id) handleZip(id, ws) + pid.kill() + } else if (id == data.id) { + pid.kill() + handleZip(id, ws) + } } } }