From ea8bd323c7e86275bce343cf51fb9c49c08dffe5 Mon Sep 17 00:00:00 2001 From: undefined Date: Mon, 1 Nov 2021 10:24:32 +0800 Subject: [PATCH] core: contest file download --- packages/hydrooj/package.json | 2 +- packages/hydrooj/src/handler/problem.ts | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index c1d5aa3a5..3ed5aa878 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "3.1.20", + "version": "3.1.21", "bin": "bin/hydrooj.js", "main": "src/loader", "module": "src/loader", diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index f468818d8..7e86964cb 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -313,14 +313,27 @@ export class ProblemDetailHandler extends ProblemHandler { this.extraTitleContent = this.pdoc.title; } - // eslint-disable-next-line @typescript-eslint/no-unused-vars - async get(..._args: any[]) { + @query('tid', Types.ObjectID, true) + async get(...args: any[]) { // Navigate to current additional file download // e.g. ![img](a.jpg) will navigate to ![img](./pid/file/a.jpg) if (!this.request.json) { - this.response.body.pdoc.content = this.response.body.pdoc.content - .replace(/\(file:\/\//g, `(./${this.pdoc.docId}/file/`) - .replace(/="file:\/\//g, `="./${this.pdoc.docId}/file/`); + if (args[1]) { + console.log(this.response.body.pdoc.content); + this.response.body.pdoc.content = this.response.body.pdoc.content + .replace(/\(file:\/\/(.+?)\)/g, (str) => { + const info = str.match(/\(file:\/\/(.+?)\)/); + return `(./${this.pdoc.docId}/file/${info[1]}${info[1].includes('?') ? '&' : '?'}tid=${args[1]})`; + }) + .replace(/="file:\/\//g, (str) => { + const info = str.match(/="file:\/\/(.+?)"/); + return `="./${this.pdoc.docId}/file/${info[1]}${info[1].includes('?') ? '&' : '?'}tid=${args[1]}"`; + }); + } else { + this.response.body.pdoc.content = this.response.body.pdoc.content + .replace(/\(file:\/\//g, `(./${this.pdoc.docId}/file/`) + .replace(/="file:\/\//g, `="./${this.pdoc.docId}/file/`); + } } this.response.body.page_name = this.tdoc ? this.tdoc.rule === 'homework'