judge: fix generate with http adapter

This commit is contained in:
undefined committed 2023-12-16 04:17:31 +08:00
1 parent 18088ed7ed
commit e9c93e6cfc
2 files changed
+18 -12

No files matched your search

+8 -4
View File
@@ -37,11 +37,12 @@ export default class Hydro implements Session {
return superagent.get(url).set('Cookie', this.config.cookie); 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(); 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('Cookie', this.config.cookie)
.set('Accept', 'application/json'); .set('Accept', 'application/json');
return data ? t.send(data) : t;
} }
async init() { async init() {
@@ -135,8 +136,11 @@ export default class Hydro implements Session {
return target; return target;
} }
async postFile(target: string, file: string) { async postFile(target: string, filename: string, file: string) {
await this.post('judge/upload', { target }).attach('file', fs.createReadStream(file)); await this.post('judge/upload')
.field('rid', target)
.field('name', filename)
.attach('file', fs.createReadStream(file));
} }
getLang(name: string, doThrow = true) { getLang(name: string, doThrow = true) {
+10 -8
View File
@@ -32,7 +32,8 @@ export const judge = async (ctx: JudgeTask) => {
{ {
stdin: { content: ctx.input || '' }, stdin: { content: ctx.input || '' },
copyIn: executeGenerator.copyIn, copyIn: executeGenerator.copyIn,
copyOut: ['stdout'], copyOut: ['stderr'],
copyOutCached: ['stdout'],
time: parseTimeMS('2s'), time: parseTimeMS('2s'),
memory: parseMemoryMB('256m'), memory: parseMemoryMB('256m'),
}, },
@@ -44,10 +45,10 @@ export const judge = async (ctx: JudgeTask) => {
return res.fileIds['stdout'] ? client.deleteFile(res.fileIds['stdout']) : Promise.resolve(); return res.fileIds['stdout'] ? client.deleteFile(res.fileIds['stdout']) : Promise.resolve();
}); });
const { const {
code, signalled, time, memory, fileIds, code, signalled, time, memory, fileIds, stderr,
} = res; } = res;
let { status } = res; let { status } = res;
const message: string[] = []; const message = [stderr.substring(0, 1024)];
if (time > parseTimeMS(ctx.config.time || '2s')) { if (time > parseTimeMS(ctx.config.time || '2s')) {
status = STATUS.STATUS_TIME_LIMIT_EXCEEDED; status = STATUS.STATUS_TIME_LIMIT_EXCEEDED;
} else if (memory > parseMemoryMB('256m') * 1024) { } else if (memory > parseMemoryMB('256m') * 1024) {
@@ -61,7 +62,7 @@ export const judge = async (ctx: JudgeTask) => {
totalMemory = Math.max(memory, totalMemory); totalMemory = Math.max(memory, totalMemory);
totalStatus = Math.max(status, totalStatus); totalStatus = Math.max(status, totalStatus);
if (status === STATUS.STATUS_ACCEPTED) { 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); await ctx.session.postFile(ctx.request.rid.toString(), `${i}.in`, tmp);
} }
ctx.next({ ctx.next({
@@ -83,7 +84,8 @@ export const judge = async (ctx: JudgeTask) => {
{ {
stdin, stdin,
copyIn: executeStd.copyIn, copyIn: executeStd.copyIn,
copyOut: ['stdout'], copyOut: ['stderr'],
copyOutCached: ['stdout'],
time: parseTimeMS('2s'), time: parseTimeMS('2s'),
memory: parseMemoryMB('256m'), memory: parseMemoryMB('256m'),
}, },
@@ -95,10 +97,10 @@ export const judge = async (ctx: JudgeTask) => {
return res.fileIds['stdout'] ? client.deleteFile(res.fileIds['stdout']) : Promise.resolve(); return res.fileIds['stdout'] ? client.deleteFile(res.fileIds['stdout']) : Promise.resolve();
}); });
const { const {
code, signalled, time, memory, fileIds, code, signalled, time, memory, fileIds, stderr,
} = res; } = res;
let { status } = res; let { status } = res;
const message: string[] = []; const message = [stderr.substring(0, 1024)];
if (time > parseTimeMS(ctx.config.time || '2s')) { if (time > parseTimeMS(ctx.config.time || '2s')) {
status = STATUS.STATUS_TIME_LIMIT_EXCEEDED; status = STATUS.STATUS_TIME_LIMIT_EXCEEDED;
} else if (memory > parseMemoryMB('256m') * 1024) { } else if (memory > parseMemoryMB('256m') * 1024) {
@@ -112,7 +114,7 @@ export const judge = async (ctx: JudgeTask) => {
totalMemory = Math.max(memory, totalMemory); totalMemory = Math.max(memory, totalMemory);
totalStatus = Math.max(status, totalStatus); totalStatus = Math.max(status, totalStatus);
if (status === STATUS.STATUS_ACCEPTED) { 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); await ctx.session.postFile(ctx.request.rid.toString(), `${i}.out`, tmp);
} }
ctx.next({ ctx.next({