From e9c93e6cfc0d736f52f9be7445895fe43ed819a3 Mon Sep 17 00:00:00 2001 From: undefined Date: Sat, 16 Dec 2023 04:17:31 +0800 Subject: [PATCH] judge: fix generate with http adapter --- packages/hydrojudge/src/hosts/hydro.ts | 12 ++++++++---- packages/hydrojudge/src/judge/generate.ts | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/hydrojudge/src/hosts/hydro.ts b/packages/hydrojudge/src/hosts/hydro.ts index 547527337..ac1617a4e 100644 --- a/packages/hydrojudge/src/hosts/hydro.ts +++ b/packages/hydrojudge/src/hosts/hydro.ts @@ -37,11 +37,12 @@ export default class Hydro implements Session { return superagent.get(url).set('Cookie', this.config.cookie); } - post(url: string, data: any) { + post(url: string, data?: any) { url = new URL(url, this.config.server_url).toString(); - return superagent.post(url).send(data) + const t = superagent.post(url) .set('Cookie', this.config.cookie) .set('Accept', 'application/json'); + return data ? t.send(data) : t; } async init() { @@ -135,8 +136,11 @@ export default class Hydro implements Session { return target; } - async postFile(target: string, file: string) { - await this.post('judge/upload', { target }).attach('file', fs.createReadStream(file)); + async postFile(target: string, filename: string, file: string) { + await this.post('judge/upload') + .field('rid', target) + .field('name', filename) + .attach('file', fs.createReadStream(file)); } getLang(name: string, doThrow = true) { diff --git a/packages/hydrojudge/src/judge/generate.ts b/packages/hydrojudge/src/judge/generate.ts index 3c2ceb8bf..e9b0d31b8 100644 --- a/packages/hydrojudge/src/judge/generate.ts +++ b/packages/hydrojudge/src/judge/generate.ts @@ -32,7 +32,8 @@ export const judge = async (ctx: JudgeTask) => { { stdin: { content: ctx.input || '' }, copyIn: executeGenerator.copyIn, - copyOut: ['stdout'], + copyOut: ['stderr'], + copyOutCached: ['stdout'], time: parseTimeMS('2s'), memory: parseMemoryMB('256m'), }, @@ -44,10 +45,10 @@ export const judge = async (ctx: JudgeTask) => { return res.fileIds['stdout'] ? client.deleteFile(res.fileIds['stdout']) : Promise.resolve(); }); const { - code, signalled, time, memory, fileIds, + code, signalled, time, memory, fileIds, stderr, } = res; let { status } = res; - const message: string[] = []; + const message = [stderr.substring(0, 1024)]; if (time > parseTimeMS(ctx.config.time || '2s')) { status = STATUS.STATUS_TIME_LIMIT_EXCEEDED; } else if (memory > parseMemoryMB('256m') * 1024) { @@ -61,7 +62,7 @@ export const judge = async (ctx: JudgeTask) => { totalMemory = Math.max(memory, totalMemory); totalStatus = Math.max(status, totalStatus); if (status === STATUS.STATUS_ACCEPTED) { - await client.getFile(fileIds['output'], tmp); + await client.getFile(fileIds['stdout'], tmp); await ctx.session.postFile(ctx.request.rid.toString(), `${i}.in`, tmp); } ctx.next({ @@ -83,7 +84,8 @@ export const judge = async (ctx: JudgeTask) => { { stdin, copyIn: executeStd.copyIn, - copyOut: ['stdout'], + copyOut: ['stderr'], + copyOutCached: ['stdout'], time: parseTimeMS('2s'), memory: parseMemoryMB('256m'), }, @@ -95,10 +97,10 @@ export const judge = async (ctx: JudgeTask) => { return res.fileIds['stdout'] ? client.deleteFile(res.fileIds['stdout']) : Promise.resolve(); }); const { - code, signalled, time, memory, fileIds, + code, signalled, time, memory, fileIds, stderr, } = res; let { status } = res; - const message: string[] = []; + const message = [stderr.substring(0, 1024)]; if (time > parseTimeMS(ctx.config.time || '2s')) { status = STATUS.STATUS_TIME_LIMIT_EXCEEDED; } else if (memory > parseMemoryMB('256m') * 1024) { @@ -112,7 +114,7 @@ export const judge = async (ctx: JudgeTask) => { totalMemory = Math.max(memory, totalMemory); totalStatus = Math.max(status, totalStatus); if (status === STATUS.STATUS_ACCEPTED) { - await client.getFile(fileIds['output'], tmp); + await client.getFile(fileIds['stdout'], tmp); await ctx.session.postFile(ctx.request.rid.toString(), `${i}.out`, tmp); } ctx.next({