core: fix config load

This commit is contained in:
undefined committed 2021-04-16 22:12:13 +08:00
1 parent b0df7024e6
commit 6bbcd983a3
1 file changed
+3 -3
+3 -3
View File
@@ -10,7 +10,7 @@ interface ParseResult {
timeMin: number, timeMin: number,
} }
export async function parseConfig(config: string | ProblemConfig) { export async function parseConfig(config: string | ProblemConfig = {}) {
const result: ParseResult = { const result: ParseResult = {
count: 0, count: 0,
memoryMin: Number.MAX_SAFE_INTEGER, memoryMin: Number.MAX_SAFE_INTEGER,
@@ -19,10 +19,10 @@ export async function parseConfig(config: string | ProblemConfig) {
timeMax: 0, timeMax: 0,
}; };
let cfg: ProblemConfig = {}; let cfg: ProblemConfig = {};
if (typeof config === 'string') { if (typeof config === 'string' && config.length) {
// TODO should validate here? // TODO should validate here?
cfg = await readYamlCases(load(config) as Record<string, any>) as ProblemConfig; cfg = await readYamlCases(load(config) as Record<string, any>) as ProblemConfig;
} else cfg = config; } else if (typeof config === 'object') cfg = config;
if (cfg.subtasks.length) { if (cfg.subtasks.length) {
for (const subtask of cfg.subtasks) { for (const subtask of cfg.subtasks) {
result.memoryMax = Math.max(result.memoryMax, subtask.memory); result.memoryMax = Math.max(result.memoryMax, subtask.memory);