From a3fb2cbd47a5d1bffe6dcc21ea9a3de0d7f4ca49 Mon Sep 17 00:00:00 2001 From: undefined Date: Wed, 22 Dec 2021 20:18:25 +0800 Subject: [PATCH] core: enhanced pdf support --- packages/hydrooj/package.json | 2 +- packages/hydrooj/src/handler/problem.ts | 2 +- packages/ui-default/backendlib/markdown-it-media.js | 3 ++- packages/ui-default/package.json | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index d3e4f72c3..adad7b575 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "3.2.28", + "version": "3.2.29", "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 37f33b86e..520616748 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -628,7 +628,7 @@ export class ProblemFileDownloadHandler extends ProblemDetailHandler { this.response.etag = file.etag; this.response.body = await storage.get(target); this.response.type = file['Content-Type'] || fileType; - this.response.disposition = `attachment; filename=${encodeURIComponent(filename)}`; + if (!noDisposition) this.response.disposition = `attachment; filename=${encodeURIComponent(filename)}`; } else { this.response.redirect = await storage.signDownloadLink( target, noDisposition ? undefined : filename, false, 'user', diff --git a/packages/ui-default/backendlib/markdown-it-media.js b/packages/ui-default/backendlib/markdown-it-media.js index 5126b28f2..1002a04c0 100644 --- a/packages/ui-default/backendlib/markdown-it-media.js +++ b/packages/ui-default/backendlib/markdown-it-media.js @@ -103,7 +103,7 @@ module.exports = function videoPlugin(md) { pdf: videoUrl, }; md.renderer.rules.video = function tokenizeReturn(tokens, idx) { - const videoID = md.utils.escapeHtml(tokens[idx].videoID); + let videoID = md.utils.escapeHtml(tokens[idx].videoID); const service = md.utils.escapeHtml(tokens[idx].service).toLowerCase(); const checkUrl = /http(?:s?):\/\/(?:www\.)?[a-zA-Z0-9-:.]{1,}\/render(?:\/)?[a-zA-Z0-9.&;?=:%]{1,}url=http(?:s?):\/\/[a-zA-Z0-9 -:.]{1,}\/[a-zA-Z0-9]{1,5}\/\?[a-zA-Z0-9.=:%]{1,}/; let num; @@ -120,6 +120,7 @@ module.exports = function videoPlugin(md) { + ' }); '; } if (service === 'pdf') { + if (videoID.startsWith('file://')) videoID += '?noDisposition=1'; return `\ diff --git a/packages/ui-default/package.json b/packages/ui-default/package.json index 136192603..79a5258c4 100644 --- a/packages/ui-default/package.json +++ b/packages/ui-default/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/ui-default", - "version": "4.27.13", + "version": "4.27.14", "author": "undefined ", "license": "AGPL-3.0", "main": "hydro.js",