From 95b04192b3d46416646799abea392fa425da0dd5 Mon Sep 17 00:00:00 2001 From: ck <21735205+cyperdark@users.noreply.github.com> Date: Mon, 9 Dec 2024 15:53:20 +0300 Subject: [PATCH] fix: Do not create empty folder before extracting & send actual error --- packages/common/utils/unzip.ts | 9 +++------ packages/server/router/index.ts | 9 +++++---- packages/server/utils/commands.ts | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/common/utils/unzip.ts b/packages/common/utils/unzip.ts index daf65324..69aa4edd 100644 --- a/packages/common/utils/unzip.ts +++ b/packages/common/utils/unzip.ts @@ -5,15 +5,12 @@ import { wLogger } from './logger'; export const unzip = (zipPath: string, extractPath: string): Promise => new Promise((resolve, reject) => { - if (!fs.existsSync(extractPath)) { - fs.mkdirSync(extractPath); - } - const zip = new AdmZip(zipPath); try { - // Extract all contents of the zip file to the specified destination - zip.extractAllTo(extractPath, /* overwrite */ true); + if (!fs.existsSync(extractPath)) fs.mkdirSync(extractPath); + + zip.extractAllTo(extractPath, true); resolve(extractPath); } catch (error) { wLogger.error('[unzip]', (error as any).message); diff --git a/packages/server/router/index.ts b/packages/server/router/index.ts index 9aa0eea9..623a22c5 100644 --- a/packages/server/router/index.ts +++ b/packages/server/router/index.ts @@ -107,6 +107,7 @@ export default function buildBaseApi(server: Server) { }) .catch((reason) => { fs.unlinkSync(tempPath); + wLogger.error( '[overlay-unzip]', folderName, @@ -115,7 +116,7 @@ export default function buildBaseApi(server: Server) { wLogger.debug('[overlay-unzip]', folderName, reason); sendJson(res, { - error: reason + error: (reason as Error).message }); }); }; @@ -131,7 +132,7 @@ export default function buildBaseApi(server: Server) { wLogger.debug(`[overlay-download]`, folderName, reason); sendJson(res, { - error: reason + error: (reason as Error).message }); }); } @@ -241,7 +242,7 @@ export default function buildBaseApi(server: Server) { wLogger.debug(`[overlay-settings]`, folderName, settings); return sendJson(res, { - error: settings.name + error: settings.message }); } @@ -285,7 +286,7 @@ export default function buildBaseApi(server: Server) { ); return sendJson(res, { - error: result.name + error: result.message }); } diff --git a/packages/server/utils/commands.ts b/packages/server/utils/commands.ts index 90729945..6b981f43 100644 --- a/packages/server/utils/commands.ts +++ b/packages/server/utils/commands.ts @@ -49,7 +49,7 @@ export function handleSocketCommands(data: string, socket: ModifiedWebsocket) { ); if (result instanceof Error) { message = { - error: result.name + error: result.message }; break; }