mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: syzoj: testdata_download
This commit is contained in:
1 parent
3469f624ab
commit
e593ebd879
5 files changed
+13
-11
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/hydrojudge",
|
"name": "@hydrooj/hydrojudge",
|
||||||
"bin": "bin/hydrojudge.js",
|
"bin": "bin/hydrojudge.js",
|
||||||
"version": "2.1.29",
|
"version": "2.1.30",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"author": "masnn",
|
"author": "masnn",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
@@ -165,8 +165,7 @@ async function read1(folder: string, files: string[], checkFile) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function readAutoCases(folder, { next }) {
|
async function readAutoCases(folder, { next }) {
|
||||||
const
|
const config = {
|
||||||
config = {
|
|
||||||
checker_type: 'default',
|
checker_type: 'default',
|
||||||
count: 0,
|
count: 0,
|
||||||
subtasks: [],
|
subtasks: [],
|
||||||
@@ -187,7 +186,7 @@ async function readAutoCases(folder, { next }) {
|
|||||||
let result = await read0(folder, files, checkFile);
|
let result = await read0(folder, files, checkFile);
|
||||||
if (!result.count) result = await read1(folder, files, checkFile);
|
if (!result.count) result = await read1(folder, files, checkFile);
|
||||||
Object.assign(config, result);
|
Object.assign(config, result);
|
||||||
next({ message: { message: 'Found {0} testcases.', params: config.count } });
|
next({ message: { message: 'Found {0} testcases.', params: [config.count] } });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new SystemError('Cannot parse testdata.', [e]);
|
throw new SystemError('Cannot parse testdata.', [e]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,7 +160,6 @@ const checkers: Record<string, Checker> = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async testlib(config) {
|
async testlib(config) {
|
||||||
console.log(config);
|
|
||||||
const { stderr, status } = await run('${dir}/checker ${dir}/in ${dir}/user_out ${dir}/answer', {
|
const { stderr, status } = await run('${dir}/checker ${dir}/in ${dir}/user_out ${dir}/answer', {
|
||||||
copyIn: {
|
copyIn: {
|
||||||
in: { src: config.input },
|
in: { src: config.input },
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.14.0",
|
"version": "2.14.1",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import os from 'os';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import superagent from 'superagent';
|
import superagent from 'superagent';
|
||||||
import { filter } from 'lodash';
|
import { filter } from 'lodash';
|
||||||
|
import { PassThrough } from 'stream';
|
||||||
import AdmZip from 'adm-zip';
|
import AdmZip from 'adm-zip';
|
||||||
import { ValidationError, RemoteOnlineJudgeError } from '../error';
|
import { ValidationError, RemoteOnlineJudgeError } from '../error';
|
||||||
import { streamToBuffer } from '../utils';
|
import { streamToBuffer } from '../utils';
|
||||||
@@ -86,15 +87,17 @@ class ProblemImportSYZOJHandler extends Handler {
|
|||||||
filenameList: result.body.testData.map((node) => node.filename),
|
filenameList: result.body.testData.map((node) => node.filename),
|
||||||
});
|
});
|
||||||
const urls = {};
|
const urls = {};
|
||||||
|
if (r.body.error) return;
|
||||||
for (const t of r.body.downloadInfo) urls[t.filename] = t.downloadUrl;
|
for (const t of r.body.downloadInfo) urls[t.filename] = t.downloadUrl;
|
||||||
const zip = new AdmZip();
|
const zip = new AdmZip();
|
||||||
for (const f of result.body.testData) {
|
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
|
// eslint-disable-next-line no-await-in-loop
|
||||||
const c = await superagent.get(urls[f.filename]);
|
zip.addFile(f.filename, await streamToBuffer(p));
|
||||||
// eslint-disable-next-line no-await-in-loop
|
|
||||||
zip.addFile(f.filename, await streamToBuffer(c));
|
|
||||||
}
|
}
|
||||||
await problem.setTestdata(domainId, docId, zip.toBuffer());
|
await problem.setTestdata(domainId, docId, zip.toBuffer());
|
||||||
|
if (judge) {
|
||||||
await problem.edit(domainId, docId, {
|
await problem.edit(domainId, docId, {
|
||||||
config: {
|
config: {
|
||||||
time: `${judge.timeLimit}ms`,
|
time: `${judge.timeLimit}ms`,
|
||||||
@@ -102,9 +105,10 @@ class ProblemImportSYZOJHandler extends Handler {
|
|||||||
// TODO other config
|
// TODO other config
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
})().catch(logger.error);
|
})().catch(logger.error);
|
||||||
this.response.body = { pid: pid || docId };
|
this.response.body = { pid: docId };
|
||||||
this.response.redirect = this.url('problem_settings', { pid: pid || docId });
|
this.response.redirect = this.url('problem_settings', { pid: docId });
|
||||||
} else {
|
} else {
|
||||||
const res = await superagent.get(`${url}export`);
|
const res = await superagent.get(`${url}export`);
|
||||||
assert(res.status === 200, new RemoteOnlineJudgeError('Cannot connect to target server'));
|
assert(res.status === 200, new RemoteOnlineJudgeError('Cannot connect to target server'));
|
||||||
|
|||||||
Reference in new issue
Block a user