mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
修复 @param 在类扩展时作用域污染的问题,完善interface
This commit is contained in:
1 parent
cd6938dd6c
commit
dd7914e1fb
31 files changed
+269
-179
No files matched your search
@@ -11,7 +11,7 @@ async function _download(url: string, path: string, retry: number) {
|
||||
return path;
|
||||
}
|
||||
|
||||
export default function download(url: string, path: string | undefined | null, retry = 3) {
|
||||
export default function download(url: string, path?: string, retry = 3) {
|
||||
if (path) return _download(url, path, retry);
|
||||
return superagent.get(url).retry(retry);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import assert from 'assert';
|
||||
import superagent from 'superagent';
|
||||
import download from './download';
|
||||
import { ValidationError, RemoteOnlineJudgeError } from '../error';
|
||||
|
||||
const RE_SYZOJ = /https?:\/\/([a-zA-Z0-9.]+)\/problem\/([0-9]+)\/?/i;
|
||||
|
||||
export async function syzoj(url: string, handler: any) {
|
||||
assert(url.match(RE_SYZOJ), new ValidationError('url'));
|
||||
if (!url.endsWith('/')) url += '/';
|
||||
const [, host, pid] = RE_SYZOJ.exec(url);
|
||||
const res = await superagent.get(`${url}export`);
|
||||
assert(res.status === 200, new RemoteOnlineJudgeError('Cannot connect to target server'));
|
||||
assert(res.body.success, new RemoteOnlineJudgeError((res.body.error || {}).message));
|
||||
const p = res.body.obj;
|
||||
const content = [];
|
||||
if (p.description) {
|
||||
content.push(
|
||||
handler.translate('problem.import.problem_description'),
|
||||
p.description,
|
||||
);
|
||||
}
|
||||
if (p.input_format) {
|
||||
content.push(
|
||||
handler.translate('problem.import.input_format'),
|
||||
p.input_format,
|
||||
);
|
||||
}
|
||||
if (p.output_format) {
|
||||
content.push(
|
||||
handler.translate('problem.import.output_format'),
|
||||
p.output_format,
|
||||
);
|
||||
}
|
||||
if (p.hint) {
|
||||
content.push(
|
||||
handler.translate('problem.import.hint'),
|
||||
p.hint,
|
||||
);
|
||||
}
|
||||
if (p.limit_and_hint) {
|
||||
content.push(
|
||||
handler.translate('problem.import.limit_and_hint'),
|
||||
p.limit_and_hint,
|
||||
);
|
||||
}
|
||||
if (p.have_additional_file) {
|
||||
content.push(
|
||||
handler.translate('problem.import.additional_file'),
|
||||
`${url}download/additional_file`,
|
||||
);
|
||||
}
|
||||
const pdoc = {
|
||||
title: p.title,
|
||||
content: content.join(' \n'),
|
||||
owner: handler.user._id,
|
||||
from: url,
|
||||
pid: `${host}_${pid}`,
|
||||
tags: p.tags,
|
||||
config: {
|
||||
time: p.time_limit,
|
||||
memory: p.memory_limit * 1024,
|
||||
filename: p.file_io_input_name,
|
||||
type: p.type,
|
||||
},
|
||||
};
|
||||
const r = download(`${url}testdata/download`);
|
||||
return [pdoc, r];
|
||||
}
|
||||
|
||||
global.Hydro.lib['import.syzoj'] = syzoj;
|
||||
+1
-1
@@ -56,7 +56,7 @@ export function size(s, base = 1) {
|
||||
return '{0} {1}'.format(Math.round(s * unit), unitNames[unitNames.length - 1]);
|
||||
}
|
||||
|
||||
export function _digit2(number: number) {
|
||||
function _digit2(number: number) {
|
||||
if (number < 10) return `0${number}`;
|
||||
return number.toString();
|
||||
}
|
||||
|
||||
@@ -17,4 +17,5 @@ async function readConfig(filePath: string) {
|
||||
}
|
||||
|
||||
global.Hydro.lib.readConfig = readConfig;
|
||||
|
||||
export default readConfig;
|
||||
@@ -9,4 +9,3 @@ export function icon(str: string) {
|
||||
}
|
||||
|
||||
global.Hydro.lib.useragent = { parse, icon };
|
||||
export default { parse, icon };
|
||||
Reference in new issue
Block a user