From eaf86997f437b94b289644eb1cd6d759bc8a62ad Mon Sep 17 00:00:00 2001 From: Menci Date: Tue, 29 Nov 2016 17:35:43 +0800 Subject: [PATCH] Add download testdata --- modules/problem.js | 19 +++++++++++++++++++ views/problem.ejs | 1 + 2 files changed, 20 insertions(+) diff --git a/modules/problem.js b/modules/problem.js index a0fb05f..ba58fdd 100644 --- a/modules/problem.js +++ b/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 + }); + } +}); diff --git a/views/problem.ejs b/views/problem.ejs index 37afe25..707d0cb 100644 --- a/views/problem.ejs +++ b/views/problem.ejs @@ -23,6 +23,7 @@
提交 提交记录 + 下载测试数据 <% if (problem.allowedEdit) { %> 编辑题面 上传测试数据