From 6bbcd983a387da2af938e892503adfd21627bd0e Mon Sep 17 00:00:00 2001 From: undefined Date: Fri, 16 Apr 2021 22:12:13 +0800 Subject: [PATCH] core: fix config load --- packages/hydrooj/src/lib/testdataConfig.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/hydrooj/src/lib/testdataConfig.ts b/packages/hydrooj/src/lib/testdataConfig.ts index 7d16e4d4..4c2f6655 100644 --- a/packages/hydrooj/src/lib/testdataConfig.ts +++ b/packages/hydrooj/src/lib/testdataConfig.ts @@ -10,7 +10,7 @@ interface ParseResult { timeMin: number, } -export async function parseConfig(config: string | ProblemConfig) { +export async function parseConfig(config: string | ProblemConfig = {}) { const result: ParseResult = { count: 0, memoryMin: Number.MAX_SAFE_INTEGER, @@ -19,10 +19,10 @@ export async function parseConfig(config: string | ProblemConfig) { timeMax: 0, }; let cfg: ProblemConfig = {}; - if (typeof config === 'string') { + if (typeof config === 'string' && config.length) { // TODO should validate here? cfg = await readYamlCases(load(config) as Record) as ProblemConfig; - } else cfg = config; + } else if (typeof config === 'object') cfg = config; if (cfg.subtasks.length) { for (const subtask of cfg.subtasks) { result.memoryMax = Math.max(result.memoryMax, subtask.memory);