Skip to content

Commit

Permalink
Merge pull request #1550 from gettakaro/increase-file-upload-size
Browse files Browse the repository at this point in the history
Allow 25MB file uploads for imports
  • Loading branch information
niekcandaele authored Sep 29, 2024
2 parents 4ccc5ac + c1e8ee6 commit 9e7f20b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/app-api/src/controllers/GameServerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GameServerOutputDTO[]> {
@Type(() => GameServerOutputDTO)
Expand Down
10 changes: 10 additions & 0 deletions packages/lib-http/src/middleware/errorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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;
}
Expand Down

0 comments on commit 9e7f20b

Please sign in to comment.