mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
fix zip utils
This commit is contained in:
3 files changed
+8
-3
No files matched your search
@@ -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
|
||||
|
||||
@@ -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 = '') {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user