core: contest file download

This commit is contained in:
undefined committed 2021-11-01 10:24:32 +08:00
1 parent 5c5864a7c2
commit ea8bd323c7
2 files changed
+19 -6

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "3.1.20",
"version": "3.1.21",
"bin": "bin/hydrooj.js",
"main": "src/loader",
"module": "src/loader",
+18 -5
View File
@@ -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'