From 2b4dbfb4b9377b522c97ad012eacbd13df529090 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Wed, 11 Jan 2023 11:41:26 -0800 Subject: [PATCH] Convert _APP_STORAGE_DEVICE env var to lowercase This is done for backwards compatibility. Up to utopia-php/storage version 0.12.X, the devices were not lowercase. Starting 0.13.X, they are all converted to lowercase, but people would still have the old case in their .env file. This change makes the value check insensitive so that the value from older versions still works. --- app/config/variables.php | 4 ++-- app/controllers/api/storage.php | 2 +- app/executor.php | 2 +- app/init.php | 2 +- app/workers/builds.php | 2 +- src/Appwrite/Resque/Worker.php | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/config/variables.php b/app/config/variables.php index 19139c0d75..193e167b8f 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -482,9 +482,9 @@ return [ ], [ 'name' => '_APP_STORAGE_DEVICE', - 'description' => 'Select default storage device. The default value is \'Local\'. List of supported adapters are \'Local\', \'S3\', \'DOSpaces\', \'Backblaze\', \'Linode\' and \'Wasabi\'.', + 'description' => 'Select default storage device. The default value is \'local\'. List of supported adapters are \'local\', \'s3\', \'dospaces\', \'backblaze\', \'linode\' and \'wasabi\'.', 'introduction' => '0.13.0', - 'default' => 'Local', + 'default' => 'local', 'required' => false, 'question' => '', ], diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 1ea72f49e8..6ecf93e25e 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -501,7 +501,7 @@ App::post('/v1/storage/buckets/:bucketId/files') } if ($chunksUploaded === $chunks) { - if (App::getEnv('_APP_STORAGE_ANTIVIRUS') === 'enabled' && $bucket->getAttribute('antivirus', true) && $fileSize <= APP_LIMIT_ANTIVIRUS && App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL) === Storage::DEVICE_LOCAL) { + if (App::getEnv('_APP_STORAGE_ANTIVIRUS') === 'enabled' && $bucket->getAttribute('antivirus', true) && $fileSize <= APP_LIMIT_ANTIVIRUS && strtolower(App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL)) === Storage::DEVICE_LOCAL) { $antivirus = new Network( App::getEnv('_APP_STORAGE_ANTIVIRUS_HOST', 'clamav'), (int) App::getEnv('_APP_STORAGE_ANTIVIRUS_PORT', 3310) diff --git a/app/executor.php b/app/executor.php index fba8c4c416..316794b929 100644 --- a/app/executor.php +++ b/app/executor.php @@ -119,7 +119,7 @@ function logError(Throwable $error, string $action, Utopia\Route $route = null) function getStorageDevice($root): Device { - switch (App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL)) { + switch (strtolower(App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL))) { case Storage::DEVICE_LOCAL: default: return new Local($root); diff --git a/app/init.php b/app/init.php index b05950d679..427ffa822f 100644 --- a/app/init.php +++ b/app/init.php @@ -968,7 +968,7 @@ App::setResource('deviceBuilds', function ($project) { function getDevice($root): Device { - switch (App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL)) { + switch (strtolower(App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL))) { case Storage::DEVICE_LOCAL: default: return new Local($root); diff --git a/app/workers/builds.php b/app/workers/builds.php index 5f33ed4010..fdd633f84a 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -91,7 +91,7 @@ class BuildsV1 extends Worker 'outputPath' => '', 'runtime' => $function->getAttribute('runtime'), 'source' => $deployment->getAttribute('path'), - 'sourceType' => App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL), + 'sourceType' => strtolower(App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL)), 'stdout' => '', 'stderr' => '', 'endTime' => null, diff --git a/src/Appwrite/Resque/Worker.php b/src/Appwrite/Resque/Worker.php index dd7cebd084..1e9918a156 100644 --- a/src/Appwrite/Resque/Worker.php +++ b/src/Appwrite/Resque/Worker.php @@ -284,7 +284,7 @@ abstract class Worker */ public function getDevice($root): Device { - switch (App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL)) { + switch (strtolower(App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL))) { case Storage::DEVICE_LOCAL: default: return new Local($root);