core: syzoj: testdata_download

This commit is contained in:
undefined committed 2020-12-06 12:40:45 +08:00
1 parent 3469f624ab
commit e593ebd879
5 files changed
+26 -24

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@hydrooj/hydrojudge",
"bin": "bin/hydrojudge.js",
"version": "2.1.29",
"version": "2.1.30",
"main": "package.json",
"author": "masnn",
"repository": "https://github.com/hydro-dev/Hydro.git",
+8 -9
View File
@@ -165,14 +165,13 @@ async function read1(folder: string, files: string[], checkFile) {
}
async function readAutoCases(folder, { next }) {
const
config = {
checker_type: 'default',
count: 0,
subtasks: [],
judge_extra_files: [],
user_extra_files: [],
};
const config = {
checker_type: 'default',
count: 0,
subtasks: [],
judge_extra_files: [],
user_extra_files: [],
};
const checkFile = ensureFile(folder);
try {
const files = await fs.readdir(folder);
@@ -187,7 +186,7 @@ async function readAutoCases(folder, { next }) {
let result = await read0(folder, files, checkFile);
if (!result.count) result = await read1(folder, files, checkFile);
Object.assign(config, result);
next({ message: { message: 'Found {0} testcases.', params: config.count } });
next({ message: { message: 'Found {0} testcases.', params: [config.count] } });
} catch (e) {
throw new SystemError('Cannot parse testdata.', [e]);
}
-1
View File
@@ -160,7 +160,6 @@ const checkers: Record<string, Checker> = {
},
async testlib(config) {
console.log(config);
const { stderr, status } = await run('${dir}/checker ${dir}/in ${dir}/user_out ${dir}/answer', {
copyIn: {
in: { src: config.input },
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.14.0",
"version": "2.14.1",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
+16 -12
View File
@@ -4,6 +4,7 @@ import os from 'os';
import assert from 'assert';
import superagent from 'superagent';
import { filter } from 'lodash';
import { PassThrough } from 'stream';
import AdmZip from 'adm-zip';
import { ValidationError, RemoteOnlineJudgeError } from '../error';
import { streamToBuffer } from '../utils';
@@ -86,25 +87,28 @@ class ProblemImportSYZOJHandler extends Handler {
filenameList: result.body.testData.map((node) => node.filename),
});
const urls = {};
if (r.body.error) return;
for (const t of r.body.downloadInfo) urls[t.filename] = t.downloadUrl;
const zip = new AdmZip();
for (const f of result.body.testData) {
const p = new PassThrough();
superagent.get(urls[f.filename]).pipe(p);
// eslint-disable-next-line no-await-in-loop
const c = await superagent.get(urls[f.filename]);
// eslint-disable-next-line no-await-in-loop
zip.addFile(f.filename, await streamToBuffer(c));
zip.addFile(f.filename, await streamToBuffer(p));
}
await problem.setTestdata(domainId, docId, zip.toBuffer());
await problem.edit(domainId, docId, {
config: {
time: `${judge.timeLimit}ms`,
memory: `${judge.memoryLimit}m`,
// TODO other config
},
});
if (judge) {
await problem.edit(domainId, docId, {
config: {
time: `${judge.timeLimit}ms`,
memory: `${judge.memoryLimit}m`,
// TODO other config
},
});
}
})().catch(logger.error);
this.response.body = { pid: pid || docId };
this.response.redirect = this.url('problem_settings', { pid: pid || docId });
this.response.body = { pid: docId };
this.response.redirect = this.url('problem_settings', { pid: docId });
} else {
const res = await superagent.get(`${url}export`);
assert(res.status === 200, new RemoteOnlineJudgeError('Cannot connect to target server'));