mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
fps: 增加文件大小限制
This commit is contained in:
1 parent
8af14294b2
commit
fa9396afd0
2 files changed
+7
-3
No files matched your search
@@ -10,7 +10,7 @@ import { buildContent } from 'hydrooj/dist/lib/content';
|
|||||||
import { ProblemAdd } from 'hydrooj/dist/lib/ui';
|
import { ProblemAdd } from 'hydrooj/dist/lib/ui';
|
||||||
import * as solution from 'hydrooj/dist/model/solution';
|
import * as solution from 'hydrooj/dist/model/solution';
|
||||||
import { PERM } from 'hydrooj/dist/model/builtin';
|
import { PERM } from 'hydrooj/dist/model/builtin';
|
||||||
import { ValidationError } from 'hydrooj/dist/error';
|
import { BadRequestError, ValidationError } from 'hydrooj/dist/error';
|
||||||
|
|
||||||
class FpsProblemImportHandler extends Handler {
|
class FpsProblemImportHandler extends Handler {
|
||||||
async get() {
|
async get() {
|
||||||
@@ -63,6 +63,8 @@ class FpsProblemImportHandler extends Handler {
|
|||||||
if (!this.request.files.file) throw new ValidationError('file');
|
if (!this.request.files.file) throw new ValidationError('file');
|
||||||
const tasks = [];
|
const tasks = [];
|
||||||
try {
|
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 content = fs.readFile(this.request.files.file.path).toString();
|
||||||
const result = await xml2js.parseStringPromise(content);
|
const result = await xml2js.parseStringPromise(content);
|
||||||
tasks.push(result);
|
tasks.push(result);
|
||||||
@@ -70,7 +72,9 @@ class FpsProblemImportHandler extends Handler {
|
|||||||
const zip = new AdmZip(this.request.files.file.path);
|
const zip = new AdmZip(this.request.files.file.path);
|
||||||
for (const entry of zip.getEntries()) {
|
for (const entry of zip.getEntries()) {
|
||||||
try {
|
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);
|
const result = await xml2js.parseStringPromise(content);
|
||||||
tasks.push(result);
|
tasks.push(result);
|
||||||
} catch { } // eslint-disable-line no-empty
|
} catch { } // eslint-disable-line no-empty
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/fps-importer",
|
"name": "@hydrooj/fps-importer",
|
||||||
"version": "1.1.6",
|
"version": "1.1.7",
|
||||||
"description": "Import FPS problems",
|
"description": "Import FPS problems",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
Reference in new issue
Block a user