From e7945a104fad7593b7c92208f778d3234592a7e9 Mon Sep 17 00:00:00 2001 From: undefined Date: Wed, 8 Feb 2023 09:46:16 +0800 Subject: [PATCH] core: remove stupid isbinaryfile --- packages/hydrooj/package.json | 1 - packages/hydrooj/src/handler/problem.ts | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 4b671f92..a6a984fd 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -29,7 +29,6 @@ "fs-extra": "^11.1.0", "graphql": "^16.6.0", "graphql-scalars": "1.20.1", - "isbinaryfile": "^5.0.0", "js-yaml": "^4.1.0", "koa": "^2.14.1", "koa-body": "^6.0.1", diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index b7fcbc79..c0f7d3a4 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -1,6 +1,5 @@ import AdmZip from 'adm-zip'; import { readFile, statSync } from 'fs-extra'; -import { isBinaryFile } from 'isbinaryfile'; import { escapeRegExp, flattenDeep, intersection, pick, uniqBy, } from 'lodash'; @@ -524,8 +523,9 @@ export class ProblemSubmitHandler extends ProblemDetailHandler { if (!file || file.size === 0) throw new ValidationError('code'); const sizeLimit = config.type === 'submit_answer' ? 128 * 1024 * 1024 : 65535; if (file.size > sizeLimit) throw new ValidationError('file'); - if (config.type !== 'submit_answer' || (file.size < 65535 && !await isBinaryFile(file.filepath, file.size))) { + if (file.size < 65535 && !file.filepath.endsWith('.zip')) { // TODO auto detect & convert encoding + // TODO submission file shape code = await readFile(file.filepath, 'utf-8'); } else { const id = nanoid();