diff --git a/.env b/.env index d7cbde1fdc..ffd61bb934 100644 --- a/.env +++ b/.env @@ -29,7 +29,7 @@ _APP_CONNECTIONS_DB_CONSOLE=db_fra1_01=mariadb://user:password@mariadb:3306/appw _APP_CONNECTIONS_CACHE=redis_fra1_01=redis://redis:6379 _APP_CONNECTIONS_QUEUE=redis_fra1_01=redis://redis:6379 _APP_CONNECTIONS_PUBSUB=redis_fra1_01=redis://redis:6379 -_APP_CONNECTIONS_STORAGE=file://localhost +_APP_CONNECTIONS_STORAGE=local://localhost _APP_STORAGE_ANTIVIRUS=disabled _APP_STORAGE_ANTIVIRUS_HOST=clamav _APP_STORAGE_ANTIVIRUS_PORT=3310 diff --git a/app/config/variables.php b/app/config/variables.php index 1fbc98e028..401326fc33 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -509,7 +509,7 @@ return [ ], [ 'name' => '_APP_CONNECTIONS_STORAGE', - 'description' => 'A DSN representing the storage device to connect to. The DSN takes the following format ://:@:/?region=. For example, for S3: \'s3://access_key:access_secret@host:port/bucket?region=us-east-1\'. To use the local filesystem, you can leave this variable empty. Available devices are file, s3, dospaces, linode, backblaze and wasabi.', + 'description' => 'A DSN representing the storage device to connect to. The DSN takes the following format ://:@:/?region=. For example, for S3: \'s3://access_key:access_secret@host:port/bucket?region=us-east-1\'. To use the local filesystem, you can leave this variable empty. Available devices are local, s3, dospaces, linode, backblaze and wasabi.', 'introduction' => '1.1.0', 'default' => '', 'required' => false, diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 876c4ebca6..71979cca55 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -41,6 +41,7 @@ use Utopia\Validator\HexColor; use Utopia\Validator\Range; use Utopia\Validator\Text; use Utopia\Validator\WhiteList; +use Utopia\DSN\DSN; use Utopia\Swoole\Request; App::post('/v1/storage/buckets') @@ -494,16 +495,7 @@ App::post('/v1/storage/buckets/:bucketId/files') } if ($chunksUploaded === $chunks) { - $connection = App::getEnv('_APP_CONNECTIONS_STORAGE', ''); /** @TODO : move this to the registry or someplace else */ - $device = STORAGE_DEVICE_LOCAL; - try { - $dsn = new DSN($connection); - $device = $dsn->getScheme(); - } catch (\Exception $e) { - $device = STORAGE_DEVICE_LOCAL; - } - - if (App::getEnv('_APP_STORAGE_ANTIVIRUS') === 'enabled' && $bucket->getAttribute('antivirus', true) && $fileSize <= APP_LIMIT_ANTIVIRUS && $device === STORAGE_DEVICE_LOCAL) { + if (App::getEnv('_APP_STORAGE_ANTIVIRUS') === 'enabled' && $bucket->getAttribute('antivirus', true) && $fileSize <= APP_LIMIT_ANTIVIRUS && $deviceFiles->getType() === 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/init.php b/app/init.php index cfa5e3118e..66ec6e160b 100644 --- a/app/init.php +++ b/app/init.php @@ -75,6 +75,7 @@ use PHPMailer\PHPMailer\PHPMailer; use Swoole\Database\PDOProxy; use Utopia\CLI\Console; use Utopia\Queue; +use Utopia\Storage\Storage; const APP_NAME = 'Appwrite'; const APP_DOMAIN = 'appwrite.io'; @@ -159,13 +160,6 @@ const DELETE_TYPE_SCHEDULES = 'schedules'; const COMPRESSION_TYPE_NONE = 'none'; const COMPRESSION_TYPE_GZIP = 'gzip'; const COMPRESSION_TYPE_ZSTD = 'zstd'; -// Storage Device Types -const STORAGE_DEVICE_LOCAL = 'file'; -const STORAGE_DEVICE_S3 = 's3'; -const STORAGE_DEVICE_DO_SPACES = 'dospaces'; -const STORAGE_DEVICE_BACKBLAZE = 'backblaze'; -const STORAGE_DEVICE_LINODE = 'linode'; -const STORAGE_DEVICE_WASABI = 'wasabi'; // Mail Types const MAIL_TYPE_VERIFICATION = 'verification'; const MAIL_TYPE_MAGIC_SESSION = 'magicSession'; @@ -1030,6 +1024,7 @@ App::setResource('console', function () { 'legalAddress' => '', 'legalTaxId' => '', 'auths' => [ + 'invites' => false, 'limit' => (App::getEnv('_APP_CONSOLE_WHITELIST_ROOT', 'enabled') === 'enabled') ? 1 : 0, // limit signup to 1 user 'duration' => Auth::TOKEN_EXPIRATION_LOGIN_LONG, // 1 Year in seconds ], @@ -1105,7 +1100,7 @@ function getDevice($root): Device $connection = App::getEnv('_APP_CONNECTIONS_STORAGE', ''); $acl = 'private'; - $device = STORAGE_DEVICE_LOCAL; + $device = Storage::DEVICE_LOCAL; $accessKey = ''; $accessSecret = ''; $bucket = ''; @@ -1119,22 +1114,21 @@ function getDevice($root): Device $bucket = $dsn->getPath(); $region = $dsn->getParam('region'); } catch (\Exception $e) { - Console::error($e->getMessage() . 'Invalid DSN. Defaulting to Local storage.'); - $device = STORAGE_DEVICE_LOCAL; + Console::error($e->getMessage() . 'Invalid DSN. Defaulting to Local device.'); } switch ($device) { - case STORAGE_DEVICE_S3: + case Storage::DEVICE_S3: return new S3($root, $accessKey, $accessSecret, $bucket, $region, $acl); - case STORAGE_DEVICE_DO_SPACES: + case STORAGE::DEVICE_DO_SPACES: return new DOSpaces($root, $accessKey, $accessSecret, $bucket, $region, $acl); - case STORAGE_DEVICE_BACKBLAZE: + case Storage::DEVICE_BACKBLAZE: return new Backblaze($root, $accessKey, $accessSecret, $bucket, $region, $acl); - case STORAGE_DEVICE_LINODE: + case Storage::DEVICE_LINODE: return new Linode($root, $accessKey, $accessSecret, $bucket, $region, $acl); - case STORAGE_DEVICE_WASABI: + case Storage::DEVICE_WASABI: return new Wasabi($root, $accessKey, $accessSecret, $bucket, $region, $acl); - case 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 898e2053ff..6b2cfcf66b 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -11,10 +11,11 @@ use Utopia\Database\DateTime; use Utopia\App; use Utopia\CLI\Console; use Utopia\Database\ID; -use Utopia\Storage\Storage; +use Utopia\DSN\DSN; use Utopia\Database\Document; use Utopia\Config\Config; use Utopia\Database\Validator\Authorization; +use Utopia\Storage\Storage; require_once __DIR__ . '/../init.php'; @@ -80,12 +81,12 @@ class BuildsV1 extends Worker } $connection = App::getEnv('_APP_CONNECTIONS_STORAGE', ''); /** @TODO : move this to the registry or someplace else */ - $device = STORAGE_DEVICE_LOCAL; + $device = Storage::DEVICE_LOCAL; try { $dsn = new DSN($connection); $device = $dsn->getScheme(); } catch (\Exception $e) { - $device = STORAGE_DEVICE_LOCAL; + Console::error($e->getMessage() . 'Invalid DSN. Defaulting to Local device.'); } $buildId = $deployment->getAttribute('buildId', ''); diff --git a/app/workers/messaging.php b/app/workers/messaging.php index 8373d07ba3..4c82a1abff 100644 --- a/app/workers/messaging.php +++ b/app/workers/messaging.php @@ -1,17 +1,16 @@ args['recipient']], - content: $this->args['message'], - from: $this->from, - ); + $recipient = $this->args['recipient']; + $message = $this->args['message']; try { - $this->sms->send($message); + $this->sms->send($this->from, $recipient, $message); } catch (\Exception $error) { throw new Exception('Error sending message: ' . $error->getMessage(), 500); } diff --git a/composer.json b/composer.json index ea97a5fbd0..2d61a9dcca 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,6 @@ "utopia-php/orchestration": "0.9.*", "utopia-php/platform": "0.3.*", "utopia-php/pools": "0.4.*", - "utopia-php/swoole": "0.5.*", "utopia-php/preloader": "0.2.*", "utopia-php/domains": "1.1.*", "utopia-php/framework": "0.25.*", @@ -64,7 +63,8 @@ "utopia-php/logger": "0.3.*", "utopia-php/messaging": "0.1.*", "utopia-php/registry": "0.5.*", - "utopia-php/storage": "0.11.*", + "utopia-php/storage": "0.13.*", + "utopia-php/swoole": "0.5.*", "utopia-php/websocket": "0.1.0", "resque/php-resque": "1.3.6", "matomo/device-detector": "6.0.0", diff --git a/composer.lock b/composer.lock index 432a5706d3..d450e93cb9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9fe0bbf14cd780146eed867f2d50e955", + "content-hash": "2b8002030d115fd67f57b89a9972f104", "packages": [ { "name": "adhocore/jwt", @@ -2573,16 +2573,16 @@ }, { "name": "utopia-php/storage", - "version": "0.11.0", + "version": "0.13.0", "source": { "type": "git", "url": "https://github.com/utopia-php/storage.git", - "reference": "59802cf281d1976560cf6e353f250a9b870efddc" + "reference": "f34c010e4f8394a6b4aff70b6de55041d9a145d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/storage/zipball/59802cf281d1976560cf6e353f250a9b870efddc", - "reference": "59802cf281d1976560cf6e353f250a9b870efddc", + "url": "https://api.github.com/repos/utopia-php/storage/zipball/f34c010e4f8394a6b4aff70b6de55041d9a145d3", + "reference": "f34c010e4f8394a6b4aff70b6de55041d9a145d3", "shasum": "" }, "require": { @@ -2622,9 +2622,9 @@ ], "support": { "issues": "https://github.com/utopia-php/storage/issues", - "source": "https://github.com/utopia-php/storage/tree/0.11.0" + "source": "https://github.com/utopia-php/storage/tree/0.13.0" }, - "time": "2022-08-31T09:17:31+00:00" + "time": "2022-11-17T15:10:18+00:00" }, { "name": "utopia-php/swoole", diff --git a/src/Appwrite/Resque/Worker.php b/src/Appwrite/Resque/Worker.php index 8503e18c3c..479855504d 100644 --- a/src/Appwrite/Resque/Worker.php +++ b/src/Appwrite/Resque/Worker.php @@ -7,9 +7,9 @@ use Utopia\App; use Utopia\Cache\Cache; use Utopia\Config\Config; use Utopia\Cache\Adapter\Sharding; +use Utopia\CLI\Console; use Utopia\Database\Database; use Utopia\Storage\Device; -use Utopia\Storage\Storage; use Utopia\Storage\Device\Local; use Utopia\Storage\Device\DOSpaces; use Utopia\Storage\Device\Linode; @@ -19,6 +19,7 @@ use Utopia\Storage\Device\S3; use Utopia\Database\Document; use Utopia\Database\Validator\Authorization; use Utopia\DSN\DSN; +use Utopia\Storage\Storage; abstract class Worker { @@ -280,7 +281,7 @@ abstract class Worker $connection = App::getEnv('_APP_CONNECTIONS_STORAGE', ''); $acl = 'private'; - $device = STORAGE_DEVICE_LOCAL; + $device = Storage::DEVICE_LOCAL; $accessKey = ''; $accessSecret = ''; $bucket = ''; @@ -294,22 +295,21 @@ abstract class Worker $bucket = $dsn->getPath(); $region = $dsn->getParam('region'); } catch (\Exception $e) { - Console::error($e->getMessage() . 'Invalid DSN. Defaulting to Local storage.'); - $device = STORAGE_DEVICE_LOCAL; + Console::error($e->getMessage() . 'Invalid DSN. Defaulting to Local device.'); } switch ($device) { - case STORAGE_DEVICE_S3: + case Storage::DEVICE_S3: return new S3($root, $accessKey, $accessSecret, $bucket, $region, $acl); - case STORAGE_DEVICE_DO_SPACES: + case STORAGE::DEVICE_DO_SPACES: return new DOSpaces($root, $accessKey, $accessSecret, $bucket, $region, $acl); - case STORAGE_DEVICE_BACKBLAZE: + case Storage::DEVICE_BACKBLAZE: return new Backblaze($root, $accessKey, $accessSecret, $bucket, $region, $acl); - case STORAGE_DEVICE_LINODE: + case Storage::DEVICE_LINODE: return new Linode($root, $accessKey, $accessSecret, $bucket, $region, $acl); - case STORAGE_DEVICE_WASABI: + case Storage::DEVICE_WASABI: return new Wasabi($root, $accessKey, $accessSecret, $bucket, $region, $acl); - case STORAGE_DEVICE_LOCAL: + case Storage::DEVICE_LOCAL: default: return new Local($root); }