Browse Source

Add download testdata

pull/6/head
Menci 8 years ago
parent
commit
eaf86997f4
  1. 19
      modules/problem.js
  2. 1
      views/problem.ejs

19
modules/problem.js

@ -241,3 +241,22 @@ app.post('/submit/:id', async (req, res) => {
});
}
});
app.get('/problem/:id/download', async (req, res) => {
try {
let id = parseInt(req.params.id);
let problem = await Problem.fromID(id);
if (!problem) throw 'No such problem';
if (!await problem.isAllowedUseBy(res.locals.user)) throw 'Permission denied';
await problem.loadRelationships();
res.download(problem.testdata.getPath(), `testdata_${id}.zip`);
} catch (e) {
syzoj.log(err);
res.render('error', {
err: err
});
}
});

1
views/problem.ejs

@ -23,6 +23,7 @@
<div class="ui buttons">
<a class="small ui primary button" href="<%= syzoj.utils.makeUrl(['submit', problem.id]) %>">提交</a>
<a class="small ui positive button" href="<%= syzoj.utils.makeUrl(['judge_state'], { problem_id: problem.id }) %>">提交记录</a>
<a class="small ui yellow button" href="<%= syzoj.utils.makeUrl(['problem', problem.id, 'download']) %>">下载测试数据</a>
<% if (problem.allowedEdit) { %>
<a class="small ui button" href="<%= syzoj.utils.makeUrl(['problem', problem.id, 'edit']) %>">编辑题面</a>
<a class="small ui button" href="<%= syzoj.utils.makeUrl(['problem', problem.id, 'upload']) %>">上传测试数据</a>

Loading…
Cancel
Save