diff --git a/models/contest.js b/models/contest.js index 1edbbbc..21261ec 100644 --- a/models/contest.js +++ b/models/contest.js @@ -135,6 +135,11 @@ class Contest extends Model { return now >= this.start_time && now < this.end_time; } + async isEnded(now) { + if (!now) now = syzoj.utils.getCurrentDate(); + return now >= this.end_time; + } + getModel() { return model; } } diff --git a/modules/contest.js b/modules/contest.js index 1ca7ea7..62a04db 100644 --- a/modules/contest.js +++ b/modules/contest.js @@ -250,7 +250,9 @@ app.get('/contest/:id/:pid', async (req, res) => { try { let contest_id = parseInt(req.params.id); let contest = await Contest.fromID(contest_id); - if (!await contest.isRunning()) throw 'The contest has ended or not started.' + + contest.ended = await contest.isEnded(); + if (!(await contest.isRunning() || contest.ended)) throw 'The contest has not started.' let problems_id = await contest.getProblems(); diff --git a/views/problem.ejs b/views/problem.ejs index 75b581e..7a31548 100644 --- a/views/problem.ejs +++ b/views/problem.ejs @@ -45,11 +45,16 @@ if (contest) {
- 提交 - <% if (contest) { %> + <% if (typeof contest !== 'undefined' && contest) { %> + <% if (!contest.ended) { %> + 提交 + <% } else { %> + 转到题库 + <% } %> 提交记录 返回比赛 <% } else { %> + 提交 提交记录 统计 下载测试数据 @@ -112,6 +117,13 @@ if (contest) {
<% } %> + <% let noSubmit = false; %> + <% + if (typeof contest !== 'undefined' && contest && contest.ended) { + noSubmit = true; + } + %> + <% if (!noSubmit) { %>
<% @@ -147,6 +159,7 @@ if (contest) {
+ <% } %>