mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: add FileTooLargeError
This commit is contained in:
1 parent
4a294f59a8
commit
1b53bfa2b4
8 files changed
+42
-27
No files matched your search
@@ -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 { BadRequestError, ValidationError } from 'hydrooj/dist/error';
|
||||
import { FileTooLargeError, ValidationError } from 'hydrooj/dist/error';
|
||||
|
||||
class FpsProblemImportHandler extends Handler {
|
||||
async get() {
|
||||
@@ -64,7 +64,7 @@ class FpsProblemImportHandler extends Handler {
|
||||
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');
|
||||
if (file.size > 64 * 1024 * 1024) throw new FileTooLargeError('64m');
|
||||
const content = fs.readFile(this.request.files.file.path).toString();
|
||||
const result = await xml2js.parseStringPromise(content);
|
||||
tasks.push(result);
|
||||
@@ -73,7 +73,7 @@ class FpsProblemImportHandler extends Handler {
|
||||
for (const entry of zip.getEntries()) {
|
||||
try {
|
||||
const buf = entry.getData();
|
||||
if (buf.byteLength > 64 * 1024 * 1024) throw new BadRequestError('File too large');
|
||||
if (buf.byteLength > 64 * 1024 * 1024) throw new FileTooLargeError('64m');
|
||||
const content = buf.toString();
|
||||
const result = await xml2js.parseStringPromise(content);
|
||||
tasks.push(result);
|
||||
|
||||
Reference in new issue
Block a user