Browse Source

Fix link to additional files during contests

pull/6/head
Pisces000221 8 years ago
parent
commit
09b2047f96
  1. 1
      modules/contest.js
  2. 13
      modules/problem.js
  3. 2
      views/problem.ejs

1
modules/contest.js

@ -337,6 +337,7 @@ app.get('/contest/:id/:pid', async (req, res) => {
let problem_id = problems_id[pid - 1];
let problem = await Problem.fromID(problem_id);
await problem.loadRelationships();
contest.ended = await contest.isEnded();
if (!(await contest.isRunning() || contest.ended)) {

13
modules/problem.js

@ -749,7 +749,18 @@ app.get('/problem/:id/download/additional_file', async (req, res) => {
let problem = await Problem.fromID(id);
if (!problem) throw new ErrorMessage('无此题目。');
if (!await problem.isAllowedUseBy(res.locals.user)) throw new ErrorMessage('您没有权限进行此操作。');
// XXX: Reduce duplication (see the '/problem/:id/submit' handler)
let contest_id = parseInt(req.query.contest_id);
if (contest_id) {
let contest = await Contest.fromID(contest_id);
if (!contest) throw new ErrorMessage('无此比赛。');
if (!await contest.isRunning()) throw new ErrorMessage('比赛未开始或已结束。');
let problems_id = await contest.getProblems();
if (!problems_id.includes(id)) throw new ErrorMessage('无此题目。');
} else {
if (!await problem.isAllowedUseBy(res.locals.user)) throw new ErrorMessage('您没有权限进行此操作。');
}
await problem.loadRelationships();

2
views/problem.ejs

@ -91,7 +91,7 @@ div[class*=ace_br] {
<a class="small ui orange button" href="<%= syzoj.utils.makeUrl(['problem', problem.id, 'statistics', problem.type === 'submit-answer' ? 'min' : 'fastest']) %>">统计</a>
<a class="small ui yellow button" href="<%= syzoj.utils.makeUrl(['problem', problem.id, 'testdata']) %>">测试数据</a>
<% } %>
<% if (problem.additional_file) { %><a class="small ui teal button" href="<%= syzoj.utils.makeUrl(['problem', problem.id, 'download', 'additional_file']) %>">附加文件</a><% } %>
<% if (problem.additional_file) { %><a class="small ui teal button" href="<%= syzoj.utils.makeUrl(['problem', problem.id, 'download', 'additional_file'], contest ? { contest_id: contest.id } : undefined) %>">附加文件</a><% } %>
</div>
<% if (!contest) { %>
<div class="ui buttons right floated">

Loading…
Cancel
Save