From 13e874d1390ebcfca64aff8c0215751c8a2eec54 Mon Sep 17 00:00:00 2001 From: undefined Date: Fri, 30 Oct 2020 23:28:00 +0800 Subject: [PATCH] =?UTF-8?q?judge:=20=E6=B5=8B=E8=AF=95=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=84=E6=95=B0=E8=BF=87=E5=A4=9A=E6=97=B6=E6=8B=92=E7=BB=9D?= =?UTF-8?q?=E8=AF=84=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install/ubuntu-1804.sh | 4 +-- packages/hydrojudge/package.json | 2 +- packages/hydrojudge/src/cases.ts | 4 ++- packages/hydrojudge/src/hosts/vj4.ts | 14 +++++------ packages/hydrojudge/src/service.ts | 2 +- .../hydrooj/src/lib/testdata.convert.ini.ts | 25 ++++++------------- 6 files changed, 21 insertions(+), 30 deletions(-) diff --git a/install/ubuntu-1804.sh b/install/ubuntu-1804.sh index f4e5dd730..862cce4de 100644 --- a/install/ubuntu-1804.sh +++ b/install/ubuntu-1804.sh @@ -6,8 +6,8 @@ db_password=$(cat /dev/urandom | head -n 10 | md5sum | head -c 20) # Basic echo "apt-get update" apt-get -qq update -echo "apt-get install curl wget unzip gnupg -y" -apt-get install -y curl wget unzip gnupg >/dev/null +echo "apt-get install curl wget gnupg -y" +apt-get install -y curl wget gnupg >/dev/null apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4 echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.0.list echo "apt-get update" diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index 5926020e2..93853d1d9 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -1,7 +1,7 @@ { "name": "@hydrooj/hydrojudge", "bin": "bin/hydrojudge.js", - "version": "2.1.14", + "version": "2.1.15", "main": "package.json", "author": "masnn", "repository": "https://github.com/hydro-dev/Hydro.git", diff --git a/packages/hydrojudge/src/cases.ts b/packages/hydrojudge/src/cases.ts index 3164f4aeb..aa7f227a3 100644 --- a/packages/hydrojudge/src/cases.ts +++ b/packages/hydrojudge/src/cases.ts @@ -293,5 +293,7 @@ export default async function readCases(folder: string, cfg: Record } else if (fs.existsSync(iniConfig)) { config = { ...convertIniConfig(fs.readFileSync(iniConfig).toString()), ...cfg }; } - return await readYamlCases(folder, config, args); + const result = await readYamlCases(folder, config, args); + if (result.count > 100) throw new FormatError('测试数据组数过多,拒绝评测'); + return result; } diff --git a/packages/hydrojudge/src/hosts/vj4.ts b/packages/hydrojudge/src/hosts/vj4.ts index 1e9981230..0db5ef580 100644 --- a/packages/hydrojudge/src/hosts/vj4.ts +++ b/packages/hydrojudge/src/hosts/vj4.ts @@ -50,7 +50,7 @@ class JudgeTask { nextWaiting = []; - constructor(session, request, ws: WebSocket) { + constructor(session: VJ4, request, ws: WebSocket) { this.stat = {}; this.stat.receive = new Date(); this.session = session; @@ -230,7 +230,7 @@ export default class VJ4 { return 'unknown'; } - async problemData(domainId: string, pid: string, savePath, retry = 3, next?) { + async problemData(domainId: string, pid: string, savePath: string, retry = 3, next?) { log.info(`Getting problem data: ${this.config.host}/${domainId}/${pid}`); await this.ensureLogin(); if (next) next({ judge_text: '正在同步测试数据,请稍后' }); @@ -249,7 +249,7 @@ export default class VJ4 { fs.ensureDirSync(path.dirname(savePath)); const zip = new AdmZip(tmpFilePath); const entries = zip.getEntries(); - if (entries.length > 1000) throw new FormatError('Too many files'); + if (entries.length > 256) throw new FormatError('Too many files'); await new Promise((resolve, reject) => { zip.extractAllToAsync(savePath, true, (e) => { if (e) reject(e); @@ -279,7 +279,7 @@ export default class VJ4 { fs.ensureDirSync(path.dirname(savePath)); const zip = new AdmZip(tmpFilePath); const entries = zip.getEntries(); - if (entries.length > 1000) throw new FormatError('Too many files'); + if (entries.length > 256) throw new FormatError('Too many files'); await new Promise((resolve, reject) => { zip.extractAllToAsync(savePath, true, (e) => { if (e) reject(e); @@ -319,7 +319,7 @@ export default class VJ4 { log.info(`[${this.config.host}] 已连接`); } - async setCookie(cookie) { + async setCookie(cookie: string) { this.config.cookie = cookie; this.axios = axios.create({ baseURL: this.config.server_url, @@ -357,7 +357,7 @@ export default class VJ4 { } } - async processData(folder) { // eslint-disable-line class-methods-use-this + async processData(folder: string) { // eslint-disable-line class-methods-use-this let files = await fs.readdir(folder); let ini = false; if (files.length <= 2) { @@ -403,7 +403,7 @@ export default class VJ4 { return filePath; } - async retry(queue) { + async retry(queue: Queue) { this.consume(queue).catch(() => { setTimeout(() => { this.retry(queue); diff --git a/packages/hydrojudge/src/service.ts b/packages/hydrojudge/src/service.ts index 6852a574e..001d6a32e 100644 --- a/packages/hydrojudge/src/service.ts +++ b/packages/hydrojudge/src/service.ts @@ -75,7 +75,7 @@ async function postInit() { fs.ensureDirSync(path.dirname(savePath)); const zip = new AdmZip(tmpFilePath); const entries = zip.getEntries(); - if (entries.length > 1000) throw new FormatError('Too many files'); + if (entries.length > 256) throw new FormatError('Too many files'); await new Promise((resolve, reject) => { zip.extractAllToAsync(savePath, true, (e) => { if (e) reject(e); diff --git a/packages/hydrooj/src/lib/testdata.convert.ini.ts b/packages/hydrooj/src/lib/testdata.convert.ini.ts index 9b0a9f344..f83b997df 100644 --- a/packages/hydrooj/src/lib/testdata.convert.ini.ts +++ b/packages/hydrooj/src/lib/testdata.convert.ini.ts @@ -3,30 +3,19 @@ import yaml from 'js-yaml'; function convert(ini: string) { const f = ini.split('\n'); const count = parseInt(f[0], 10); - const res = { cases: [] }; + const res = { subtasks: [] }; for (let i = 1; i <= count; i++) { const [input, output, time, score, memory] = f[i].split('|'); const cur = { - input, output, score: parseInt(score, 10), time: `${time}s`, memory: '128m', + cases: [{ input: `input/${input}`, output: `output/${output}` }], + score: parseInt(score, 10), + time: `${time}s`, + memory: '128m', }; if (!Number.isNaN(parseInt(memory, 10))) cur.memory = `${Math.floor(parseInt(memory, 10) / 1024)}m`; - res.cases.push(cur); + res.subtasks.push(cur); } - if (res.cases.length > 0) { - const { time, score, memory } = res.cases[0]; - for (let i = 1; i < res.cases.length; i++) { - if (res.cases[i].time !== time - || res.cases[i].score !== score - || res.cases[i].memory !== memory) { - return yaml.safeDump(res); - } - } - } - return yaml.safeDump({ - time: res.cases[0].time, - score: res.cases[0].score, - memory: res.cases[0].memory, - }); + return yaml.safeDump(res); } global.Hydro.lib['testdata.convert.ini'] = convert;