From a2d27416828cb78b6d05e42dc585d0f8fa8884ad Mon Sep 17 00:00:00 2001 From: undefined Date: Thu, 20 Nov 2025 13:23:38 +0800 Subject: [PATCH] bug fixes --- framework/utils/lib/utils.ts | 9 +++++---- packages/hydrooj/src/upgrade.ts | 1 + packages/ui-default/backendlib/markdown-it-media.ts | 5 +++-- packages/ui-default/templates/contest_problemlist.html | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/framework/utils/lib/utils.ts b/framework/utils/lib/utils.ts index 5505855cd..e3bda4868 100644 --- a/framework/utils/lib/utils.ts +++ b/framework/utils/lib/utils.ts @@ -129,6 +129,9 @@ export function bufferToStream(buffer: Buffer): NodeJS.ReadableStream { return stream; } +let ObjectId: typeof import('bson').ObjectId; // eslint-disable-line +let isMoment: (x: any) => x is Moment; + export namespace Time { export const second = 1000; export const minute = second * 60; @@ -145,15 +148,13 @@ export namespace Time { } export function getObjectID(timestamp: string | Date | Moment, allZero = true) { - let isMoment: (x: any) => x is Moment; - let ObjectId: typeof import('bson').ObjectId; // eslint-disable-line try { - ({ ObjectId } = require('bson')); + ObjectId ||= require('bson').ObjectId; } catch (e) { throw new Error('No bson module found'); } try { - ({ isMoment } = require('moment')); + isMoment ||= require('moment'); } catch (e) { throw new Error('No moment module found'); } diff --git a/packages/hydrooj/src/upgrade.ts b/packages/hydrooj/src/upgrade.ts index b18cf1722..72d51edee 100644 --- a/packages/hydrooj/src/upgrade.ts +++ b/packages/hydrooj/src/upgrade.ts @@ -638,5 +638,6 @@ export const coreScripts: MigrationScript[] = [ await rename(file.path, `contest/${domainId}/${tid}/public/${name || type}`); } } + return true; }, ]; diff --git a/packages/ui-default/backendlib/markdown-it-media.ts b/packages/ui-default/backendlib/markdown-it-media.ts index 1d9793748..f92bed9cf 100644 --- a/packages/ui-default/backendlib/markdown-it-media.ts +++ b/packages/ui-default/backendlib/markdown-it-media.ts @@ -3,6 +3,7 @@ /* eslint-disable regexp/no-useless-non-capturing-group */ /* eslint-disable regexp/optimal-quantifier-concatenation */ +import _ from 'lodash'; import type MarkdownIt from 'markdown-it'; import { v4 as uuid } from 'uuid'; @@ -101,10 +102,10 @@ export function Media(md: MarkdownIt) { if (result) return result; } if (service === 'pdf') { - if (src.startsWith('file://') || src.startsWith('./') || (src[1] === '/' && src[2] !== '/')) src += src.includes('?') ? '&noDisposition=1' : '?noDisposition=1'; + if (['file://', './', '../'].some((i) => src.startsWith(i)) || (src[1] === '/' && src[2] !== '/')) src += src.includes('?') ? '&noDisposition=1' : '?noDisposition=1'; // A response with has content-disposition header causes the browser to download the file automatically. // As we cannot control response header from external sites, we block embedding external PDFs. - else return '
Embedding an external PDF is no longer supported.
'; + else return `Embedding an external PDF is no longer supported.
Download`; return `\