|
|
@ -81,80 +81,6 @@ app.apiRouter.post('/api/v2/markdown', async (req, res) => { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// APIs for judge client
|
|
|
|
|
|
|
|
app.apiRouter.post('/api/v2/judge/peek', async (req, res) => { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if (req.query.session_id !== syzoj.config.judge_token) return res.status(404).send({ err: 'Permission denied' }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let WaitingJudge = syzoj.model('waiting_judge'); |
|
|
|
|
|
|
|
let JudgeState = syzoj.model('judge_state'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let judge_state, custom_test; |
|
|
|
|
|
|
|
await syzoj.utils.lock('/api/v2/judge/peek', async () => { |
|
|
|
|
|
|
|
let waiting_judge = await WaitingJudge.findOne({ order: [['priority', 'ASC'], ['id', 'ASC']] }); |
|
|
|
|
|
|
|
if (!waiting_judge) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (waiting_judge.type === 'submission') { |
|
|
|
|
|
|
|
judge_state = await waiting_judge.getJudgeState(); |
|
|
|
|
|
|
|
await judge_state.loadRelationships(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
custom_test = await waiting_judge.getCustomTest(); |
|
|
|
|
|
|
|
await custom_test.loadRelationships(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
await waiting_judge.destroy(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (judge_state) { |
|
|
|
|
|
|
|
if (judge_state.problem.type === 'submit-answer') { |
|
|
|
|
|
|
|
res.send({ |
|
|
|
|
|
|
|
have_task: 1, |
|
|
|
|
|
|
|
judge_id: judge_state.id, |
|
|
|
|
|
|
|
answer_file: judge_state.code, |
|
|
|
|
|
|
|
testdata: judge_state.problem.id, |
|
|
|
|
|
|
|
problem_type: judge_state.problem.type, |
|
|
|
|
|
|
|
type: 'submission' |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
res.send({ |
|
|
|
|
|
|
|
have_task: 1, |
|
|
|
|
|
|
|
judge_id: judge_state.id, |
|
|
|
|
|
|
|
code: judge_state.code, |
|
|
|
|
|
|
|
language: judge_state.language, |
|
|
|
|
|
|
|
testdata: judge_state.problem.id, |
|
|
|
|
|
|
|
time_limit: judge_state.problem.time_limit, |
|
|
|
|
|
|
|
memory_limit: judge_state.problem.memory_limit, |
|
|
|
|
|
|
|
file_io: judge_state.problem.file_io, |
|
|
|
|
|
|
|
file_io_input_name: judge_state.problem.file_io_input_name, |
|
|
|
|
|
|
|
file_io_output_name: judge_state.problem.file_io_output_name, |
|
|
|
|
|
|
|
problem_type: judge_state.problem.type, |
|
|
|
|
|
|
|
type: 'submission' |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (custom_test) { |
|
|
|
|
|
|
|
res.send({ |
|
|
|
|
|
|
|
have_task: 1, |
|
|
|
|
|
|
|
judge_id: custom_test.id, |
|
|
|
|
|
|
|
code: custom_test.code, |
|
|
|
|
|
|
|
language: custom_test.language, |
|
|
|
|
|
|
|
input_file: (await require('fs-extra').readFileAsync(custom_test.input_filepath)).toString(), |
|
|
|
|
|
|
|
time_limit: custom_test.problem.time_limit, |
|
|
|
|
|
|
|
memory_limit: custom_test.problem.memory_limit, |
|
|
|
|
|
|
|
file_io: custom_test.problem.file_io, |
|
|
|
|
|
|
|
file_io_input_name: custom_test.problem.file_io_input_name, |
|
|
|
|
|
|
|
file_io_output_name: custom_test.problem.file_io_output_name, |
|
|
|
|
|
|
|
problem_type: custom_test.problem.type, |
|
|
|
|
|
|
|
type: 'custom_test' |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
res.send({ have_task: 0 }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
res.status(500).send(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.apiRouter.post('/api/v2/judge/compiled', async (req, res) => { |
|
|
|
app.apiRouter.post('/api/v2/judge/compiled', async (req, res) => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (req.get('Token') !== syzoj.config.judge_token) return res.status(403).send({ err: 'Incorrect token' }); |
|
|
|
if (req.get('Token') !== syzoj.config.judge_token) return res.status(403).send({ err: 'Incorrect token' }); |
|
|
|