From 21c069d9984b1dfc3e052bbe4ed4c48602830ddd Mon Sep 17 00:00:00 2001 From: undefined Date: Thu, 24 Oct 2024 01:27:31 +0800 Subject: [PATCH] core: add lang.isBinary option --- packages/hydrooj/src/handler/problem.ts | 3 +-- packages/hydrooj/src/lib/content.ts | 2 +- packages/utils/lib/lang.ts | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index 7d5275c34..481209cb3 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -483,8 +483,7 @@ export class ProblemSubmitHandler extends ProblemDetailHandler { if (!file || file.size === 0) throw new ValidationError('code'); const sizeLimit = config.type === 'submit_answer' ? 128 * 1024 * 1024 : lengthLimit; if (file.size > sizeLimit) throw new ValidationError('file'); - if (file.size < lengthLimit && !file.filepath.endsWith('.zip')) { - // TODO auto detect & convert encoding + if (file.size < lengthLimit && !file.filepath.endsWith('.zip') && !setting.langs[lang].isBinary) { // TODO submission file shape code = await readFile(file.filepath, 'utf-8'); } else { diff --git a/packages/hydrooj/src/lib/content.ts b/packages/hydrooj/src/lib/content.ts index 058dd7b61..f09d94b95 100644 --- a/packages/hydrooj/src/lib/content.ts +++ b/packages/hydrooj/src/lib/content.ts @@ -8,7 +8,7 @@ export interface ProblemSource { source?: string, } -export function buildContent(source: ProblemSource, type: 'markdown' | 'html' = 'markdown', translate?: Function) { +export function buildContent(source: ProblemSource, type: 'markdown' | 'html' = 'markdown', translate?: (s: string) => string) { const _ = translate || ((s: string) => s); let cnt = 0; // Keep it for backward compatibility, but don't add to typings diff --git a/packages/utils/lib/lang.ts b/packages/utils/lib/lang.ts index f794f5a2c..6a189a9d6 100644 --- a/packages/utils/lib/lang.ts +++ b/packages/utils/lib/lang.ts @@ -15,6 +15,7 @@ export interface LangConfig { target?: string; key: string; hidden: boolean; + isBinary?: boolean; analysis?: string; /** @deprecated */ remote?: string; @@ -52,6 +53,7 @@ export function parseLang(config: string): Record { entry.key = key; entry.hidden ||= false; entry.disabled ||= false; + entry.isBinary ||= false; entry.validAs ||= {}; } return file;