From 0d86bd9ddcdad192ec044b58c767476b6f2a7694 Mon Sep 17 00:00:00 2001 From: undefined Date: Wed, 7 Apr 2021 15:43:13 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E4=BF=AE=E5=A4=8D=E6=AF=94=E8=B5=9B?= =?UTF-8?q?=E4=B8=AD=E5=BC=95=E7=94=A8=E9=99=84=E5=8A=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/hydrooj/package.json | 2 +- packages/hydrooj/src/handler/contest.ts | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 22f157885..81de76ed5 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.21.14", + "version": "2.21.15", "bin": "bin/hydrooj.js", "main": "dist/loader.js", "typings": "dist/loader.d.ts", diff --git a/packages/hydrooj/src/handler/contest.ts b/packages/hydrooj/src/handler/contest.ts index 9c23094a7..3e39ce66c 100644 --- a/packages/hydrooj/src/handler/contest.ts +++ b/packages/hydrooj/src/handler/contest.ts @@ -18,9 +18,10 @@ import record from '../model/record'; import user from '../model/user'; import message from '../model/message'; import { - Route, Handler, Types, param, + Route, Handler, Types, param, query, } from '../service/server'; import * as bus from '../service/bus'; +import storage from '../service/storage'; const ContestHandler = contest.ContestHandlerMixin(Handler); @@ -257,13 +258,18 @@ class ContestProblemHandler extends ContestHandler { } } - async get() { + // eslint-disable-next-line + async get(...args: any[]) { const path = [ ['Hydro', 'homepage'], ['contest_main', 'contest_main'], [this.tdoc.title, 'contest_detail', { tid: this.tdoc.docId }, true], [this.pdoc.title, null, null, true], ]; + // Navigate to current additional file download + // e.g. ![img](a.jpg) will navigate to ![img](./pid/file/a.jpg) + this.response.body.pdoc.content = this.response.body.pdoc.content + .replace(/\(file:\/\//g, `(./${this.pdoc.docId}/file/`); this.response.body = { tdoc: this.tdoc, pdoc: this.pdoc, @@ -276,6 +282,19 @@ class ContestProblemHandler extends ContestHandler { } } +export class ContestProblemFileDownloadHandler extends ContestProblemHandler { + @query('type', Types.Range(['additional_file', 'testdata']), true) + @param('filename', Types.String) + @param('noDisposition', Types.Boolean) + async get(domainId: string, type = 'additional_file', filename: string, noDisposition = false) { + if (type === 'testdata' && this.user._id !== this.pdoc.owner) this.checkPerm(PERM.PERM_READ_PROBLEM_DATA); + this.response.redirect = await storage.signDownloadLink( + `problem/${this.pdoc.domainId}/${this.pdoc.docId}/${type}/${filename}`, + noDisposition ? undefined : filename, false, 'user', + ); + } +} + class ContestDetailProblemSubmitHandler extends ContestProblemHandler { @param('tid', Types.ObjectID) @param('pid', Types.UnsignedInt) @@ -425,6 +444,7 @@ export async function apply() { Route('contest_scoreboard_raw', '/contest/:tid/scoreboard/raw', ContestScoreboardRawHandler, PERM.PERM_VIEW_CONTEST); Route('contest_scoreboard_download', '/contest/:tid/export/:ext', ContestScoreboardDownloadHandler, PERM.PERM_VIEW_CONTEST); Route('contest_detail_problem', '/contest/:tid/p/:pid', ContestProblemHandler, PERM.PERM_VIEW_CONTEST); + Route('contest_detail_problem_file_download', '/contest/:tid/p/:pid/file/:filename', ContestProblemFileDownloadHandler, PERM.PERM_VIEW_PROBLEM); Route('contest_detail_problem_submit', '/contest/:tid/p/:pid/submit', ContestDetailProblemSubmitHandler, PERM.PERM_VIEW_CONTEST); Route('contest_code', '/contest/:tid/code', ContestCodeHandler, PERM.PERM_VIEW_CONTEST); }