Browse Source

Update API.

master
t123yh 7 years ago
parent
commit
dfabdc16fe
  1. 6
      modules/api_v2.js
  2. 6
      modules/enums.js
  3. 44
      modules/judge.js

6
modules/api_v2.js

@ -190,9 +190,9 @@ app.apiRouter.post('/api/v2/judge/update2', async (req, res) => {
judge_state.score = data.score;
judge_state.pending = false;
judge_state.status = data.statusString;
this.total_time = data.time;
this.max_memory = data.memory;
this.result = data.result;
judge_state.total_time = data.time;
judge_state.max_memory = data.memory;
judge_state.result = data.result;
await judge_state.save();
await judge_state.updateRelatedInfo();

6
modules/enums.js

@ -0,0 +1,6 @@
var ProblemType;
(function (ProblemType) {
ProblemType[ProblemType["Standard"] = 1] = "Standard";
ProblemType[ProblemType["AnswerSubmission"] = 2] = "AnswerSubmission";
ProblemType[ProblemType["Interaction"] = 3] = "Interaction";
})(ProblemType = exports.ProblemType || (exports.ProblemType = {}));

44
modules/judge.js

@ -0,0 +1,44 @@
const enums = require('./enums'),
rp = require('request-promise'),
url = require('url');
module.exports.judge = async function (judge_state, priority) {
let type, param;
switch (judge_state.problem.type) {
case 'submit-answer':
type = enums.ProblemType.AnswerSubmission;
break;
case 'interaction':
type = enums.ProblemType.Interaction;
break;
default:
type = enums.ProblemType.Standard;
param = {
language: judge_state.language,
code: judge_state.code,
timeLimit: judge_state.problem.time_limit,
memoryLimit: judge_state.problem.memory_limit,
fileIOInput: judge_state.problem.file_io ? judge_state.problem.file_io_input_name : null,
fileIOOutput: judge_state.problem.file_io ? judge_state.problem.file_io_output_name : null
};
break;
}
const req = {
taskId: judge_state.id,
testData: judge_state.problem.id.toString(),
type: type,
priority: priority,
param: param
};
await rp(url.resolve(syzoj.config.judge_server_addr, "/daemon/task"), {
method: 'PUT',
body: req,
headers: {
Token: syzoj.config.judge_token
},
json: true,
simple: true
});
}
Loading…
Cancel
Save