fix zip utils

This commit is contained in:
undefined committed 2025-04-14 19:22:11 +08:00
1 parent 302d03fe08
commit 50d0536a3b
3 files changed
+8 -3

No files matched your search

+1 -1
View File
@@ -112,7 +112,7 @@ export default (logger, xff, xhost) => async (ctx: KoaContext, next: Next) => {
ctx.response.status = 302;
ctx.redirect(response.redirect);
} else if (response.body) {
ctx.body = response.body;
ctx.body = response.body instanceof Blob ? Buffer.from(await response.body.arrayBuffer()) : response.body;
ctx.response.status = response.status || 200;
ctx.response.type = response.type
|| (request.json
+5 -2
View File
@@ -454,6 +454,7 @@ export class ProblemModel {
const {
preferredPrefix, progress, override = false, operator = 1,
} = options;
let delSource = options.delSource;
let problems: string[];
try {
if (filepath.endsWith('.zip')) {
@@ -465,6 +466,7 @@ export class ProblemModel {
} catch (e) {
throw new ValidationError('zip', null, e.message);
}
delSource = true;
await extractZip(entries, tmpdir);
} else if (fs.statSync(filepath).isDirectory()) {
tmpdir = filepath;
@@ -478,7 +480,8 @@ export class ProblemModel {
problems = files.filter((f) => f.isDirectory()).map((i) => i.name);
}
} catch (e) {
if (options.delSource) await fs.remove(tmpdir);
if (delSource) await fs.remove(tmpdir);
throw e;
}
for (const i of problems) {
try {
@@ -622,7 +625,7 @@ export class ProblemModel {
(process.env.HYDRO_CLI ? logger.info : progress)?.(`Error importing problem ${i}: ${e.message}`);
}
}
if (options.delSource) await fs.remove(tmpdir);
if (delSource) await fs.remove(tmpdir);
}
static async export(domainId: string, pidFilter = '') {
+2
View File
@@ -348,6 +348,8 @@ export async function extractZip<T>(zipOrEntries: ZipReader<T> | Entry[], dest:
continue;
}
if (fs.existsSync(d) && !overwrite) continue;
const dir = path.dirname(d);
if (!fs.existsSync(dir)) await fs.mkdir(dir, { recursive: true });
const content = await entry.getData(Writable.toWeb(fs.createWriteStream(d)), { signal });
if (!content) throw new Error('CANT_EXTRACT_FILE');
await fs.utimes(d, entry.lastModDate, entry.lastModDate);