You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.8 KiB
JavaScript
53 lines
1.8 KiB
JavaScript
const assert = require('assert');
|
|
|
|
const { download } = global.Hydro.lib;
|
|
const { axios } = global.Hydro.lib;
|
|
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;
|