Skip to content

Commit

Permalink
fix: Do not create empty folder before extracting & send actual error
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark authored and KotRikD committed Dec 9, 2024
1 parent 9a42746 commit 95b0419
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
9 changes: 3 additions & 6 deletions packages/common/utils/unzip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ import { wLogger } from './logger';

export const unzip = (zipPath: string, extractPath: string): Promise<string> =>
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);
Expand Down
9 changes: 5 additions & 4 deletions packages/server/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export default function buildBaseApi(server: Server) {
})
.catch((reason) => {
fs.unlinkSync(tempPath);

wLogger.error(
'[overlay-unzip]',
folderName,
Expand All @@ -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
});
});
};
Expand All @@ -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
});
});
}
Expand Down Expand Up @@ -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
});
}

Expand Down Expand Up @@ -285,7 +286,7 @@ export default function buildBaseApi(server: Server) {
);

return sendJson(res, {
error: result.name
error: result.message
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/server/utils/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function handleSocketCommands(data: string, socket: ModifiedWebsocket) {
);
if (result instanceof Error) {
message = {
error: result.name
error: result.message
};
break;
}
Expand Down

0 comments on commit 95b0419

Please sign in to comment.