From 0ed001620c689be6a926a5800fd116bc25676cbc Mon Sep 17 00:00:00 2001 From: t123yh Date: Tue, 22 Aug 2017 16:41:17 +0800 Subject: [PATCH] Add support for answer-submission problems. --- libs/judger.js | 17 +++++++++++------ models/judge_state.js | 2 +- modules/problem.js | 4 +++- modules/submission.js | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/libs/judger.js b/libs/judger.js index f012aa4..e836d78 100644 --- a/libs/judger.js +++ b/libs/judger.js @@ -3,10 +3,12 @@ const enums = require('./enums'), url = require('url'); module.exports.judge = async function (judge_state, priority) { - let type, param; + let type, param, extraFile = null; switch (judge_state.problem.type) { case 'submit-answer': type = enums.ProblemType.AnswerSubmission; + param = null; + extraFile = 'static/uploads/answer/' + judge_state.code; break; case 'interaction': type = enums.ProblemType.Interaction; @@ -25,11 +27,14 @@ module.exports.judge = async function (judge_state, priority) { } const req = { - taskId: judge_state.id, - testData: judge_state.problem.id.toString(), - type: type, - priority: priority, - param: param + content: { + taskId: judge_state.id, + testData: judge_state.problem.id.toString(), + type: type, + priority: priority, + param: param + }, + extraFileLocation: extraFile }; await rp(url.resolve(syzoj.config.judge_server_addr, "/daemon/task"), { diff --git a/models/judge_state.js b/models/judge_state.js index 6fc8863..1a5dab2 100644 --- a/models/judge_state.js +++ b/models/judge_state.js @@ -82,7 +82,7 @@ class JudgeState extends Model { static async create(val) { return JudgeState.fromRecord(JudgeState.model.build(Object.assign({ code: '', - language: '', + language: null, user_id: 0, problem_id: 0, submit_time: parseInt((new Date()).getTime() / 1000), diff --git a/modules/problem.js b/modules/problem.js index 2d358c9..b385626 100644 --- a/modules/problem.js +++ b/modules/problem.js @@ -595,7 +595,7 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1 judge_state = await JudgeState.create({ code: file.md5, max_memory: size, - language: '', + language: null, user_id: res.locals.user.id, problem_id: req.params.id }); @@ -640,6 +640,8 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1 try { await Judger.judge(judge_state, contest_id ? 3 : 2); } catch (err) { + judge_state.status = "System Error"; + await judge_state.save(); throw new ErrorMessage(`无法开始评测:${err.toString()}`); } diff --git a/modules/submission.js b/modules/submission.js index bb65fa3..8a8ff40 100644 --- a/modules/submission.js +++ b/modules/submission.js @@ -32,7 +32,7 @@ const getSubmissionInfo = (s) => ({ userId: s.user_id, problemName: s.problem.title, problemId: s.problem.id, - language: s.language != null ? syzoj.config.languages[s.language].show : null, + language: (s.language != null && s.language !== '') ? syzoj.config.languages[s.language].show : null, codeSize: s.allowedSeeCode ? syzoj.utils.formatSize(s.code.length) : null, submitTime: syzoj.utils.formatDate(s.submit_time), });