mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +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.response.status = 302;
|
||||||
ctx.redirect(response.redirect);
|
ctx.redirect(response.redirect);
|
||||||
} else if (response.body) {
|
} 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.status = response.status || 200;
|
||||||
ctx.response.type = response.type
|
ctx.response.type = response.type
|
||||||
|| (request.json
|
|| (request.json
|
||||||
|
|||||||
@@ -454,6 +454,7 @@ export class ProblemModel {
|
|||||||
const {
|
const {
|
||||||
preferredPrefix, progress, override = false, operator = 1,
|
preferredPrefix, progress, override = false, operator = 1,
|
||||||
} = options;
|
} = options;
|
||||||
|
let delSource = options.delSource;
|
||||||
let problems: string[];
|
let problems: string[];
|
||||||
try {
|
try {
|
||||||
if (filepath.endsWith('.zip')) {
|
if (filepath.endsWith('.zip')) {
|
||||||
@@ -465,6 +466,7 @@ export class ProblemModel {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new ValidationError('zip', null, e.message);
|
throw new ValidationError('zip', null, e.message);
|
||||||
}
|
}
|
||||||
|
delSource = true;
|
||||||
await extractZip(entries, tmpdir);
|
await extractZip(entries, tmpdir);
|
||||||
} else if (fs.statSync(filepath).isDirectory()) {
|
} else if (fs.statSync(filepath).isDirectory()) {
|
||||||
tmpdir = filepath;
|
tmpdir = filepath;
|
||||||
@@ -478,7 +480,8 @@ export class ProblemModel {
|
|||||||
problems = files.filter((f) => f.isDirectory()).map((i) => i.name);
|
problems = files.filter((f) => f.isDirectory()).map((i) => i.name);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (options.delSource) await fs.remove(tmpdir);
|
if (delSource) await fs.remove(tmpdir);
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
for (const i of problems) {
|
for (const i of problems) {
|
||||||
try {
|
try {
|
||||||
@@ -622,7 +625,7 @@ export class ProblemModel {
|
|||||||
(process.env.HYDRO_CLI ? logger.info : progress)?.(`Error importing problem ${i}: ${e.message}`);
|
(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 = '') {
|
static async export(domainId: string, pidFilter = '') {
|
||||||
|
|||||||
@@ -348,6 +348,8 @@ export async function extractZip<T>(zipOrEntries: ZipReader<T> | Entry[], dest:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (fs.existsSync(d) && !overwrite) 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 });
|
const content = await entry.getData(Writable.toWeb(fs.createWriteStream(d)), { signal });
|
||||||
if (!content) throw new Error('CANT_EXTRACT_FILE');
|
if (!content) throw new Error('CANT_EXTRACT_FILE');
|
||||||
await fs.utimes(d, entry.lastModDate, entry.lastModDate);
|
await fs.utimes(d, entry.lastModDate, entry.lastModDate);
|
||||||
|
|||||||
Reference in new issue
Block a user