From 1c59c8d8ddda08cc27d7a9bf6f2c4fbda9982495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 1 Apr 2022 09:00:31 +0000 Subject: [PATCH] PR review changes --- app/controllers/api/storage.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 69801f1050..e37c691082 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -67,6 +67,11 @@ App::post('/v1/storage/buckets') /** @var Appwrite\Event\Event $audits */ /** @var Appwrite\Stats\Stats $usage */ + // Maximum allowed size validation + if ($maximumFileSize > (int) App::getEnv('_APP_STORAGE_LIMIT', 0)) { + throw new Exception('Bucket maximum file size is larger than _APP_STORAGE_LIMIT.', 400, Exception::ATTRIBUTE_VALUE_INVALID); + } + $bucketId = $bucketId === 'unique()' ? $dbForProject->getId() : $bucketId; try { $files = Config::getParam('collections', [])['files'] ?? []; @@ -243,7 +248,7 @@ App::put('/v1/storage/buckets/:bucketId') // Maximum allowed size validation if ($maximumFileSize > (int) App::getEnv('_APP_STORAGE_LIMIT', 0)) { - throw new Exception('Bucket maximum file size is larger than _APP_STORAGE_LIMIT.', 400, Exception::ATTRIBUTE_VALUE_INVALID); + throw new Exception('Bucket maximum file size allowed is larger than _APP_STORAGE_LIMIT.', 400, Exception::ATTRIBUTE_VALUE_INVALID); } $bucket = $dbForProject->getDocument('buckets', $bucketId); @@ -426,7 +431,7 @@ App::post('/v1/storage/buckets/:bucketId/files') $maximumFileSize = $bucket->getAttribute('maximumFileSize', 0); if ($maximumFileSize > (int) App::getEnv('_APP_STORAGE_LIMIT', 0)) { - throw new Exception('Error bucket maximum file size is larger than _APP_STORAGE_LIMIT', 500, Exception::GENERAL_SERVER_ERROR); + throw new Exception('Error bucket maximum file size is larger than _APP_STORAGE_LIMIT', 400, Exception::STORAGE_INVALID_FILE_SIZE); } $file = $request->getFiles('file');