From fb68c9bd37ee5c870c9d878d7aa1af81ef076f05 Mon Sep 17 00:00:00 2001 From: zhangyan Date: Fri, 6 Dec 2024 16:28:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangyan --- package.json | 2 +- update/update.js | 42 +++++++++++++++++++++--------------------- version.js | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index bad6983..77e1e9e 100644 --- a/package.json +++ b/package.json @@ -11,12 +11,12 @@ "child_process": "^1.0.2" }, "dependencies": { + "adm-zip": "^0.5.16", "iconv-lite": "^0.6.3", "node-windows": "^1.0.0-beta.8", "protobufjs": "^7.4.0", "require.js": "^1.0.0", "socket.io": "^4.7.5", - "unzipper": "^0.12.3", "winston": "^3.17.0", "winston-daily-rotate-file": "^5.0.0", "ws": "^8.18.0" diff --git a/update/update.js b/update/update.js index 6dd94b6..fc403d1 100644 --- a/update/update.js +++ b/update/update.js @@ -15,7 +15,7 @@ const fs = require('fs') const winston = require('winston'); const path = require('path'); -const unzipper = require('unzipper'); +const AdmZip = require('adm-zip') const { exit } = require('process'); const TypeManage = require('../typeManage.js'); const Version = require('../version.js'); @@ -40,7 +40,7 @@ function process(session_id, cmd, message) { // 返回扩展程序当前版本 logger.info(`The current version is ${Version.version.version}`); sendMsg(session_id, GET_CMD, Version.version.version) - // 升级版本 + // 升级版本 } else if (cmd === UPDATE_CMD) { // 设置标记位 if (!isUpdate) { @@ -68,25 +68,25 @@ function update(session_id, data) { sendMsg(session_id, UPDATE_FAIL_CMD, ''); return; } - // 获取项目根目录 - let rootDir = findProjectRoot(session_id, path.dirname(__dirname)); - fs.createReadStream(updateZipPath) - .pipe(unzipper.Extract({ path: rootDir})) - .promise() - .then(() => { - // 删除临时文件 - fs.unlinkSync(updateZipPath); - publishStatus(UPDATE_SUCCESS_CMD); - sendMsg(session_id, UPDATE_SUCCESS_CMD, ''); - // 正常退出进程 - exit(0); - }) - .catch((err) => { - isUpdate = false; - publishStatus(UPDATE_FAIL_CMD); - sendMsg(session_id, UPDATE_FAIL_CMD, '') - logger.error(err); - }) + try { + // 获取项目根目录 + let rootDir = findProjectRoot(session_id, path.dirname(__dirname)); + let zip = new AdmZip(updateZipPath); + zip.extractAllTo(rootDir, true); + // 删除临时文件 + fs.unlinkSync(updateZipPath); + publishStatus(UPDATE_SUCCESS_CMD); + sendMsg(session_id, UPDATE_SUCCESS_CMD, ''); + // 正常退出进程 + exit(0); + } catch (err) { + // 删除临时文件 + fs.unlinkSync(updateZipPath); + isUpdate = false; + publishStatus(UPDATE_FAIL_CMD); + sendMsg(session_id, UPDATE_FAIL_CMD, '') + logger.error(err); + } }) } diff --git a/version.js b/version.js index 28148e9..d4984dd 100644 --- a/version.js +++ b/version.js @@ -13,7 +13,7 @@ * limitations under the License. */ class version { - static version = '1.0.2'; //版本号 + static version = '1.0.3'; //版本号 } module.exports = { -- Gitee