core: 修复比赛中引用附加文件错误的问题

This commit is contained in:
undefined committed 2021-04-07 15:43:13 +08:00
1 parent 4b48c0c164
commit 0d86bd9ddc
2 files changed
+23 -3

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.21.14", "version": "2.21.15",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "dist/loader.js", "main": "dist/loader.js",
"typings": "dist/loader.d.ts", "typings": "dist/loader.d.ts",
+22 -2
View File
@@ -18,9 +18,10 @@ import record from '../model/record';
import user from '../model/user'; import user from '../model/user';
import message from '../model/message'; import message from '../model/message';
import { import {
Route, Handler, Types, param, Route, Handler, Types, param, query,
} from '../service/server'; } from '../service/server';
import * as bus from '../service/bus'; import * as bus from '../service/bus';
import storage from '../service/storage';
const ContestHandler = contest.ContestHandlerMixin(Handler); 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 = [ const path = [
['Hydro', 'homepage'], ['Hydro', 'homepage'],
['contest_main', 'contest_main'], ['contest_main', 'contest_main'],
[this.tdoc.title, 'contest_detail', { tid: this.tdoc.docId }, true], [this.tdoc.title, 'contest_detail', { tid: this.tdoc.docId }, true],
[this.pdoc.title, null, null, 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 = { this.response.body = {
tdoc: this.tdoc, tdoc: this.tdoc,
pdoc: this.pdoc, 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 { class ContestDetailProblemSubmitHandler extends ContestProblemHandler {
@param('tid', Types.ObjectID) @param('tid', Types.ObjectID)
@param('pid', Types.UnsignedInt) @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_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_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', '/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_detail_problem_submit', '/contest/:tid/p/:pid/submit', ContestDetailProblemSubmitHandler, PERM.PERM_VIEW_CONTEST);
Route('contest_code', '/contest/:tid/code', ContestCodeHandler, PERM.PERM_VIEW_CONTEST); Route('contest_code', '/contest/:tid/code', ContestCodeHandler, PERM.PERM_VIEW_CONTEST);
} }