Browse Source

Add submit code by file

master
Menci 7 years ago
parent
commit
09f7a2135f
  1. 4
      config-example.json
  2. 17
      modules/problem.js
  3. 6
      views/problem.ejs

4
config-example.json

@ -28,7 +28,9 @@
"limit": {
"time_limit": 10000,
"memory_limit": 1024,
"data_size": 209715200
"data_size": 209715200,
"submit_code": 102400,
"submit_answer": 10485760
},
"page": {
"problem": 50,

17
modules/problem.js

@ -551,10 +551,15 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
let judge_state;
if (problem.type === 'submit-answer') {
if (!req.files['answer']) throw new ErrorMessage('请上传答案文件。');
if (req.files['answer'][0].size > syzoj.config.limit.submit_answer) throw new ErrorMessage('答案文件太大。');
let File = syzoj.model('file');
let file = await File.upload(req.files['answer'][0].path, 'answer');
let size = await file.getUnzipSize();
if (size > syzoj.config.limit.submit_answer) throw new ErrorMessage('答案文件太大。');
if (!file.md5) throw new ErrorMessage('上传答案文件失败。');
judge_state = await JudgeState.create({
code: file.md5,
@ -564,8 +569,18 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
problem_id: req.params.id
});
} else {
let code;
if (req.files['answer']) {
if (req.files['answer'][0].size > syzoj.config.limit.submit_code) throw new ErrorMessage('代码文件太大。');
let fs = Promise.promisifyAll(require('fs'));
code = (await fs.readFileAsync(req.files['answer'][0].path)).toString();
} else {
if (req.body.code.length > syzoj.config.limit.submit_code) throw new ErrorMessage('代码太长。');
code = req.body.code;
}
judge_state = await JudgeState.create({
code: req.body.code,
code: code,
language: req.body.language,
user_id: res.locals.user.id,
problem_id: req.params.id

6
views/problem.ejs

@ -219,6 +219,12 @@ if (contest) {
<div class="twelve wide stretched column" style="padding-left: 0; margin-left: calc(-1rem - 1px); width: calc(75% + 1rem + 1px + 25px) !important; ">
<div id="editor" style="border: 1px solid #D4D4D5; "><% if (state) { %><%= state.code %><% } %></div>
</div>
<div class="inline fields" style="width: 100%; ">
<div class="field" style="margin: 0 auto; ">
<label for="answer">或者,上传代码文件</label>
<input type="file" id="answer" name="answer">
</div>
</div>
</div>
<% } %>
<div class="ui center aligned vertical segment" style="padding-bottom: 0; "><button type="submit" class="ui button">提交</button></div>

Loading…
Cancel
Save