diff --git a/packages/app-api/src/controllers/GameServerController.ts b/packages/app-api/src/controllers/GameServerController.ts index 8c04ddc46d..de169b2211 100644 --- a/packages/app-api/src/controllers/GameServerController.ts +++ b/packages/app-api/src/controllers/GameServerController.ts @@ -42,7 +42,14 @@ import { AllowedFilters } from './shared.js'; import multer from 'multer'; const storage = multer.memoryStorage(); -const upload = multer({ storage }); +const upload = multer({ + storage, + limits: { + // 25MB + fileSize: 25 * 1024 * 1024, + fieldSize: 25 * 1024 * 1024, + }, +}); class GameServerTypesOutputDTOAPI extends APIOutput { @Type(() => GameServerOutputDTO) diff --git a/packages/lib-http/src/middleware/errorHandler.ts b/packages/lib-http/src/middleware/errorHandler.ts index 7d47e0d358..0b10863664 100644 --- a/packages/lib-http/src/middleware/errorHandler.ts +++ b/packages/lib-http/src/middleware/errorHandler.ts @@ -3,6 +3,7 @@ import { HttpError } from 'routing-controllers'; import { logger, errors } from '@takaro/util'; import { apiResponse } from '../util/apiResponse.js'; import { ValidationError } from 'class-validator'; +import { MulterError } from 'multer'; const log = logger('errorHandler'); @@ -25,6 +26,15 @@ export async function ErrorHandler( } } + if (originalError instanceof MulterError) { + status = 400; + parsedError = new errors.BadRequestError('Invalid file'); + if (originalError.code === 'LIMIT_FIELD_VALUE') { + status = 400; + parsedError = new errors.BadRequestError('File too large'); + } + } + if (originalError instanceof HttpError) { status = originalError.httpCode; }