fps: 增加文件大小限制

This commit is contained in:
undefined committed 2021-03-03 13:13:00 +08:00
1 parent 8af14294b2
commit fa9396afd0
2 files changed
+7 -3

No files matched your search

+6 -2
View File
@@ -10,7 +10,7 @@ import { buildContent } from 'hydrooj/dist/lib/content';
import { ProblemAdd } from 'hydrooj/dist/lib/ui';
import * as solution from 'hydrooj/dist/model/solution';
import { PERM } from 'hydrooj/dist/model/builtin';
import { ValidationError } from 'hydrooj/dist/error';
import { BadRequestError, ValidationError } from 'hydrooj/dist/error';
class FpsProblemImportHandler extends Handler {
async get() {
@@ -63,6 +63,8 @@ class FpsProblemImportHandler extends Handler {
if (!this.request.files.file) throw new ValidationError('file');
const tasks = [];
try {
const file = await fs.stat(this.request.files.file.path);
if (file.size > 64 * 1024 * 1024) throw new BadRequestError('File too large');
const content = fs.readFile(this.request.files.file.path).toString();
const result = await xml2js.parseStringPromise(content);
tasks.push(result);
@@ -70,7 +72,9 @@ class FpsProblemImportHandler extends Handler {
const zip = new AdmZip(this.request.files.file.path);
for (const entry of zip.getEntries()) {
try {
const content = entry.getData().toString();
const buf = entry.getData();
if (buf.byteLength > 64 * 1024 * 1024) throw new BadRequestError('File too large');
const content = buf.toString();
const result = await xml2js.parseStringPromise(content);
tasks.push(result);
} catch { } // eslint-disable-line no-empty
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/fps-importer",
"version": "1.1.6",
"version": "1.1.7",
"description": "Import FPS problems",
"main": "package.json",
"repository": "https://github.com/hydro-dev/Hydro.git",