problem-import-syzoj
parent
00cd747768
commit
9bb94f101d
@ -0,0 +1,52 @@
|
|||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const download = global.Hydro['lib.download'];
|
||||||
|
const axios = global.Hydro['lib.axios'];
|
||||||
|
const { ValidationError, RemoteOnlineJudgeError } = global.Hydro.error;
|
||||||
|
|
||||||
|
async function syzoj(url) {
|
||||||
|
const RE_SYZOJ = /https?:\/\/([a-zA-Z0-9.]+)\/problem\/([0-9]+)\/?/i;
|
||||||
|
assert(url.match(RE_SYZOJ), new ValidationError('url'));
|
||||||
|
if (!url.endsWith('/')) url += '/';
|
||||||
|
const [, host, pid] = RE_SYZOJ.exec(url);
|
||||||
|
const res = await axios.get(`${url}export`);
|
||||||
|
assert(res.status === 200, new RemoteOnlineJudgeError('Cannot connect to target server'));
|
||||||
|
assert(res.data.success, new RemoteOnlineJudgeError((res.data.error || {}).message));
|
||||||
|
const p = res.data.obj;
|
||||||
|
const content = [
|
||||||
|
this.translate('problem.import.problem_description'),
|
||||||
|
p.description,
|
||||||
|
this.translate('problem.import.input_format'),
|
||||||
|
p.input_format,
|
||||||
|
this.translate('problem.import.output_format'),
|
||||||
|
p.output_format,
|
||||||
|
this.translate('problem.import.hint'),
|
||||||
|
p.hint,
|
||||||
|
this.translate('problem.import.limit_and_hint'),
|
||||||
|
p.limit_and_hint,
|
||||||
|
];
|
||||||
|
if (p.have_additional_file) {
|
||||||
|
content.push(
|
||||||
|
this.translate('problem.import.additional_file'),
|
||||||
|
`${url}download/additional_file`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const pdoc = {
|
||||||
|
title: p.title,
|
||||||
|
content: content.join(' \n'),
|
||||||
|
owner: this.user._id,
|
||||||
|
from: url,
|
||||||
|
pid: `${host}_${pid}`,
|
||||||
|
config: {
|
||||||
|
time: p.time_limit,
|
||||||
|
memory: p.memory_limit * 1024,
|
||||||
|
filename: p.file_io_input_name,
|
||||||
|
type: p.type,
|
||||||
|
tags: p.tags,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const r = await download(`${url}testdata/download`);
|
||||||
|
return [pdoc, r];
|
||||||
|
}
|
||||||
|
|
||||||
|
global.Hydro.handler.import.ProblemImportHandler.from_syzoj = syzoj;
|
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"name": "problem-import-syzoj",
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
Loading…
Reference in New Issue