core: remove stupid isbinaryfile

pull/511/head
undefined 2 years ago
parent 37ac2f80f7
commit e7945a104f

@ -29,7 +29,6 @@
"fs-extra": "^11.1.0", "fs-extra": "^11.1.0",
"graphql": "^16.6.0", "graphql": "^16.6.0",
"graphql-scalars": "1.20.1", "graphql-scalars": "1.20.1",
"isbinaryfile": "^5.0.0",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"koa": "^2.14.1", "koa": "^2.14.1",
"koa-body": "^6.0.1", "koa-body": "^6.0.1",

@ -1,6 +1,5 @@
import AdmZip from 'adm-zip'; import AdmZip from 'adm-zip';
import { readFile, statSync } from 'fs-extra'; import { readFile, statSync } from 'fs-extra';
import { isBinaryFile } from 'isbinaryfile';
import { import {
escapeRegExp, flattenDeep, intersection, pick, uniqBy, escapeRegExp, flattenDeep, intersection, pick, uniqBy,
} from 'lodash'; } from 'lodash';
@ -524,8 +523,9 @@ export class ProblemSubmitHandler extends ProblemDetailHandler {
if (!file || file.size === 0) throw new ValidationError('code'); if (!file || file.size === 0) throw new ValidationError('code');
const sizeLimit = config.type === 'submit_answer' ? 128 * 1024 * 1024 : 65535; const sizeLimit = config.type === 'submit_answer' ? 128 * 1024 * 1024 : 65535;
if (file.size > sizeLimit) throw new ValidationError('file'); 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 auto detect & convert encoding
// TODO submission file shape
code = await readFile(file.filepath, 'utf-8'); code = await readFile(file.filepath, 'utf-8');
} else { } else {
const id = nanoid(); const id = nanoid();

Loading…
Cancel
Save