From 4b7a080de7f391447b28df89dc1beea9f333ecde Mon Sep 17 00:00:00 2001 From: undefined Date: Mon, 7 Oct 2024 15:14:53 +0800 Subject: [PATCH] core: fix problem import --- packages/hydrooj/src/model/problem.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/hydrooj/src/model/problem.ts b/packages/hydrooj/src/model/problem.ts index 7c5420dd1..b805a4cad 100644 --- a/packages/hydrooj/src/model/problem.ts +++ b/packages/hydrooj/src/model/problem.ts @@ -480,7 +480,7 @@ export class ProblemModel { } const files = await fs.readdir(tmpdir, { withFileTypes: true }); problems = files.filter((f) => f.isDirectory()).map((i) => i.name); - } finally { + } catch (e) { if (options.delSource) await fs.remove(tmpdir); } for (const i of problems) { @@ -504,8 +504,12 @@ export class ProblemModel { } return true; }; - const getFiles = async (...type: string[]) => { - if (type.length > 1) return type.flatMap((t) => getFiles(t)); + const getFiles = async (...type: string[]): Promise<[fs.Dirent, string][]> => { + if (type.length > 1) { + let result = []; + for (const t of type) result = result.concat(await getFiles(t)); + return result; + } const [t] = type; if (!files.find((f) => f.name === t && f.isDirectory())) return []; const rs = await fs.readdir(path.join(tmpdir, i, t), { withFileTypes: true });