From 838594530f75638069329cace4392b1c7b6f58ab Mon Sep 17 00:00:00 2001 From: undefined Date: Tue, 11 Apr 2023 22:51:57 +0800 Subject: [PATCH] fps-importer: allow importing remote_judge config --- packages/fps-importer/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/fps-importer/index.ts b/packages/fps-importer/index.ts index 115857f33..490a135a1 100644 --- a/packages/fps-importer/index.ts +++ b/packages/fps-importer/index.ts @@ -3,9 +3,13 @@ import decodeHTML from 'decode-html'; import xml2js from 'xml2js'; import { _, AdmZip, BadRequestError, buildContent, ContentNode, Context, FileTooLargeError, fs, - Handler, PERM, ProblemConfigFile, ProblemModel, SolutionModel, ValidationError, + Handler, PERM, ProblemConfigFile, ProblemModel, ProblemType, SolutionModel, ValidationError, yaml, } from 'hydrooj'; +const knownRemoteMapping = { + bas: 'ybtbas', +}; + class FpsProblemImportHandler extends Handler { async get() { this.response.template = 'problem_import.html'; @@ -58,12 +62,17 @@ class FpsProblemImportHandler extends Handler { time: p.time_limit[0]._ + p.time_limit[0].$.unit, memory: p.memory_limit[0]._ + p.memory_limit[0].$.unit, }; + if (p.remote_oj) { + config.type = ProblemType.Remote; + config.subType = knownRemoteMapping[p.remote_oj[0]] || p.remote_oj[0]; + config.target = p.remote_id[0]; + } const title = decodeHTML(p.title.join(' ')); const tags = _.filter(p.source, (i: string) => i.trim()).flatMap((i) => i.split(' ')).filter((i) => i); const pid = await ProblemModel.add(domainId, null, title, buildContent(content, 'html'), this.user._id, tags); const tasks = [ ProblemModel.edit(domainId, pid, { html: true }), - ProblemModel.addTestdata(domainId, pid, 'config.yaml', Buffer.from(`time: ${config.time}\nmemory: ${config.memory}`)), + ProblemModel.addTestdata(domainId, pid, 'config.yaml', Buffer.from(yaml.dump(config))), ]; const addTestdata = (node: any, id: string, ext: string) => { if (!node && typeof node !== 'string') return; // Ignore file not exist