From 1fcc5eccb17bdb0021f66e2832541e9c87a6aeb4 Mon Sep 17 00:00:00 2001 From: Akshay Rana Date: Mon, 17 Oct 2022 12:44:44 +0530 Subject: [PATCH 01/11] updated timestamp format to ISO string in realtime payload --- app/realtime.php | 4 ++-- src/Appwrite/Messaging/Adapter/Realtime.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/realtime.php b/app/realtime.php index be87c3d6e6..0b1d992922 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -237,7 +237,7 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats, 'data' => [ 'events' => ['stats.connections'], 'channels' => ['project'], - 'timestamp' => DateTime::now(), + 'timestamp' => date('c'), 'payload' => [ $projectId => $payload[$projectId] ] @@ -264,7 +264,7 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats, 'data' => [ 'events' => ['test.event'], 'channels' => ['tests'], - 'timestamp' => DateTime::now(), + 'timestamp' => date('c'), 'payload' => $payload ] ]; diff --git a/src/Appwrite/Messaging/Adapter/Realtime.php b/src/Appwrite/Messaging/Adapter/Realtime.php index 9151a5c0b5..c595c394e4 100644 --- a/src/Appwrite/Messaging/Adapter/Realtime.php +++ b/src/Appwrite/Messaging/Adapter/Realtime.php @@ -149,7 +149,7 @@ class Realtime extends Adapter 'data' => [ 'events' => $events, 'channels' => $channels, - 'timestamp' => DateTime::now(), + 'timestamp' => date('c'), 'payload' => $payload ] ])); From c08f2e65e6e0fa201d8584483caa814ef5212f83 Mon Sep 17 00:00:00 2001 From: Akshay Rana Date: Tue, 18 Oct 2022 22:22:01 +0530 Subject: [PATCH 02/11] Updated timestamp format Co-authored-by: Steven <1477010+stnguyen90@users.noreply.github.com> --- src/Appwrite/Messaging/Adapter/Realtime.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Messaging/Adapter/Realtime.php b/src/Appwrite/Messaging/Adapter/Realtime.php index c595c394e4..91b2e5e267 100644 --- a/src/Appwrite/Messaging/Adapter/Realtime.php +++ b/src/Appwrite/Messaging/Adapter/Realtime.php @@ -149,7 +149,7 @@ class Realtime extends Adapter 'data' => [ 'events' => $events, 'channels' => $channels, - 'timestamp' => date('c'), + 'timestamp' => DateTime::formatTz(DateTime::now()), 'payload' => $payload ] ])); From 641a4af8d460361cbda5d8ab9bda6246d1c152a2 Mon Sep 17 00:00:00 2001 From: Akshay Rana Date: Tue, 18 Oct 2022 22:40:50 +0530 Subject: [PATCH 03/11] upated the timestamp code --- app/realtime.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/realtime.php b/app/realtime.php index 0b1d992922..595f43b48f 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -237,7 +237,7 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats, 'data' => [ 'events' => ['stats.connections'], 'channels' => ['project'], - 'timestamp' => date('c'), + 'timestamp' => DateTime::formatTz(DateTime::now()), 'payload' => [ $projectId => $payload[$projectId] ] @@ -264,7 +264,7 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats, 'data' => [ 'events' => ['test.event'], 'channels' => ['tests'], - 'timestamp' => date('c'), + 'timestamp' => DateTime::formatTz(DateTime::now()), 'payload' => $payload ] ]; From 29c30a361b06e9451a437aa1d8a3b7de80ebd849 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 9 Nov 2022 11:45:15 +0000 Subject: [PATCH 04/11] Fix null warnings - Fixed Avatars isset operator - Added isset operator to openSSL data in files - dns_get_record does not throw errors, instead it logs a warning and returns false. Altered code accordingly. PHP Bug Report: https://bugs.php.net/bug.php?id=73149 - --- app/controllers/api/avatars.php | 4 ++-- app/controllers/api/storage.php | 14 +++++++------- src/Appwrite/Network/Validator/CNAME.php | 4 ++++ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index b7aef1505b..25c9fe8659 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -242,8 +242,8 @@ App::get('/v1/avatars/favicon') case 'jpeg': $size = \explode('x', \strtolower($sizes)); - $sizeWidth = (int) $size[0] ?? 0; - $sizeHeight = (int) $size[1] ?? 0; + $sizeWidth = (int) ($size[0] ?? 0); + $sizeHeight = (int) ($size[1] ?? 0); if (($sizeWidth * $sizeHeight) >= $space) { $space = $sizeWidth * $sizeHeight; diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 530f174cd0..04ff10ca61 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -565,10 +565,10 @@ App::post('/v1/storage/buckets/:bucketId/files') 'comment' => '', 'chunksTotal' => $chunks, 'chunksUploaded' => $chunksUploaded, - 'openSSLVersion' => $openSSLVersion, - 'openSSLCipher' => $openSSLCipher, - 'openSSLTag' => $openSSLTag, - 'openSSLIV' => $openSSLIV, + 'openSSLVersion' => $openSSLVersion ?? null, + 'openSSLCipher' => $openSSLCipher ?? null, + 'openSSLTag' => $openSSLTag ?? null, + 'openSSLIV' => $openSSLIV ?? null, 'search' => implode(' ', [$fileId, $fileName]), 'metadata' => $metadata, ]); @@ -581,9 +581,9 @@ App::post('/v1/storage/buckets/:bucketId/files') ->setAttribute('mimeType', $mimeType) ->setAttribute('sizeActual', $sizeActual) ->setAttribute('algorithm', $algorithm) - ->setAttribute('openSSLVersion', $openSSLVersion) - ->setAttribute('openSSLCipher', $openSSLCipher) - ->setAttribute('openSSLTag', $openSSLTag) + ->setAttribute('openSSLVersion', $openSSLVersion ?? null) + ->setAttribute('openSSLCipher', $openSSLCipher ?? null) + ->setAttribute('openSSLTag', $openSSLTag ?? null) ->setAttribute('openSSLIV', $openSSLIV) ->setAttribute('metadata', $metadata) ->setAttribute('chunksUploaded', $chunksUploaded); diff --git a/src/Appwrite/Network/Validator/CNAME.php b/src/Appwrite/Network/Validator/CNAME.php index 93a302b962..678a57cecd 100644 --- a/src/Appwrite/Network/Validator/CNAME.php +++ b/src/Appwrite/Network/Validator/CNAME.php @@ -46,6 +46,10 @@ class CNAME extends Validator return false; } + if (!$records) { + return false; + } + foreach ($records as $record) { if (isset($record['target']) && $record['target'] === $this->target) { return true; From a0ab93432845fd6e807bad4921d2c6063c574996 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 9 Nov 2022 13:23:14 +0000 Subject: [PATCH 05/11] Fix another null warning --- app/controllers/api/storage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 04ff10ca61..837bb9e541 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -584,7 +584,7 @@ App::post('/v1/storage/buckets/:bucketId/files') ->setAttribute('openSSLVersion', $openSSLVersion ?? null) ->setAttribute('openSSLCipher', $openSSLCipher ?? null) ->setAttribute('openSSLTag', $openSSLTag ?? null) - ->setAttribute('openSSLIV', $openSSLIV) + ->setAttribute('openSSLIV', $openSSLIV ?? null) ->setAttribute('metadata', $metadata) ->setAttribute('chunksUploaded', $chunksUploaded); From bc915483ff96e74e9c06257e02ab76e9bb0add89 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 9 Nov 2022 13:52:46 +0000 Subject: [PATCH 06/11] Update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 2c649ab5f0..0230b0f840 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,7 @@ ## Bugs - Fix license detection for Flutter and Dart SDKs [#4435](https://github.com/appwrite/appwrite/pull/4435) - Fix missing realtime event for create function deployment [#4574](https://github.com/appwrite/appwrite/pull/4574) +- Fix a few null safety warnings [#4654](https://github.com/appwrite/appwrite/pull/4654) # Version 1.0.3 ## Bugs From a19e668d790392fce616528931801ec509da7b3d Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 14 Nov 2022 13:11:43 +0000 Subject: [PATCH 07/11] Update storage.php --- app/controllers/api/storage.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 837bb9e541..690c0050ad 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -542,6 +542,11 @@ App::post('/v1/storage/buckets/:bucketId/files') $sizeActual = $deviceFiles->getFileSize($path); $fileHash = $deviceFiles->getFileHash($path); + $openSSLVersion = null; + $openSSLCipher = null; + $openSSLTag = null; + $openSSLIV = null; + if ($bucket->getAttribute('encryption', true) && $fileSize <= APP_STORAGE_READ_BUFFER) { $openSSLVersion = '1'; $openSSLCipher = OpenSSL::CIPHER_AES_128_GCM; @@ -565,10 +570,10 @@ App::post('/v1/storage/buckets/:bucketId/files') 'comment' => '', 'chunksTotal' => $chunks, 'chunksUploaded' => $chunksUploaded, - 'openSSLVersion' => $openSSLVersion ?? null, - 'openSSLCipher' => $openSSLCipher ?? null, - 'openSSLTag' => $openSSLTag ?? null, - 'openSSLIV' => $openSSLIV ?? null, + 'openSSLVersion' => $openSSLVersion, + 'openSSLCipher' => $openSSLCipher, + 'openSSLTag' => $openSSLTag, + 'openSSLIV' => $openSSLIV, 'search' => implode(' ', [$fileId, $fileName]), 'metadata' => $metadata, ]); @@ -581,10 +586,10 @@ App::post('/v1/storage/buckets/:bucketId/files') ->setAttribute('mimeType', $mimeType) ->setAttribute('sizeActual', $sizeActual) ->setAttribute('algorithm', $algorithm) - ->setAttribute('openSSLVersion', $openSSLVersion ?? null) - ->setAttribute('openSSLCipher', $openSSLCipher ?? null) - ->setAttribute('openSSLTag', $openSSLTag ?? null) - ->setAttribute('openSSLIV', $openSSLIV ?? null) + ->setAttribute('openSSLVersion', $openSSLVersion) + ->setAttribute('openSSLCipher', $openSSLCipher) + ->setAttribute('openSSLTag', $openSSLTag) + ->setAttribute('openSSLIV', $openSSLIV) ->setAttribute('metadata', $metadata) ->setAttribute('chunksUploaded', $chunksUploaded); From 3e0456291ff3dac9c8baf4a78d33d7d14fd3fc28 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Tue, 22 Nov 2022 09:42:29 -0800 Subject: [PATCH 08/11] Update PR template 1. Ask for why in description to help with troubleshooting in the future 2. Change related PRs to a list so it renders nicer 3. Remove changes.md task in favor of just using milestones to track changes 4. Add reminder to check if API specs need to be updated --- .github/PULL_REQUEST_TEMPLATE.md | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 8522022bdb..ab59c97ff7 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -11,21 +11,17 @@ Happy contributing! ## What does this PR do? -(Provide a description of what this PR does.) +(Provide a description of what this PR does and why it's needed.) ## Test Plan -(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.) +(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Screenshots may also be helpful.) ## Related PRs and Issues -(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.) +- (Related PR or issue) -### Have you added your change to the [Changelog](https://github.com/appwrite/appwrite/blob/master/CHANGES.md)? +## Checklist -(The CHANGES.md file tracks all the changes that make it to the `main` branch. Add your change to this file in the following format) -- One line description of your PR [#pr_number](Link to your PR) - -### Have you read the [Contributing Guidelines on issues](https://github.com/appwrite/appwrite/blob/master/CONTRIBUTING.md)? - -(Write your answer here.) +- [ ] Have you read the [Contributing Guidelines on issues](https://github.com/appwrite/appwrite/blob/master/CONTRIBUTING.md)? +- [ ] If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs? From 77d4627d42442fb8d9f4750cb44e32c9c6397bc7 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 26 Nov 2022 19:45:29 +0400 Subject: [PATCH 09/11] feat: use constants in switch case --- app/controllers/api/storage.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 3c8ffc5644..fde7c6b828 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -65,7 +65,7 @@ App::post('/v1/storage/buckets') ->param('enabled', true, new Boolean(true), 'Is bucket enabled?', true) ->param('maximumFileSize', (int) App::getEnv('_APP_STORAGE_LIMIT', 0), new Range(1, (int) App::getEnv('_APP_STORAGE_LIMIT', 0)), 'Maximum file size allowed in bytes. Maximum allowed value is ' . Storage::human(App::getEnv('_APP_STORAGE_LIMIT', 0), 0) . '. For self-hosted setups you can change the max limit by changing the `_APP_STORAGE_LIMIT` environment variable. [Learn more about storage environment variables](docs/environment-variables#storage)', true) ->param('allowedFileExtensions', [], new ArrayList(new Text(64), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Allowed file extensions. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' extensions are allowed, each 64 characters long.', true) - ->param('compression', 'none', new WhiteList([COMPRESSION_TYPE_NONE, COMPRESSION_TYPE_GZIP, COMPRESSION_TYPE_ZSTD]), 'Compression algorithm choosen for compression. Can be one of ' . COMPRESSION_TYPE_NONE . ', [' . COMPRESSION_TYPE_GZIP . '](https://en.wikipedia.org/wiki/Gzip), or [' . COMPRESSION_TYPE_ZSTD . '](https://en.wikipedia.org/wiki/Zstd), For file size above ' . Storage::human(APP_STORAGE_READ_BUFFER, 0) . ' compression is skipped even if it\'s enabled', true) + ->param('compression', COMPRESSION_TYPE_NONE, new WhiteList([COMPRESSION_TYPE_NONE, COMPRESSION_TYPE_GZIP, COMPRESSION_TYPE_ZSTD]), 'Compression algorithm choosen for compression. Can be one of ' . COMPRESSION_TYPE_NONE . ', [' . COMPRESSION_TYPE_GZIP . '](https://en.wikipedia.org/wiki/Gzip), or [' . COMPRESSION_TYPE_ZSTD . '](https://en.wikipedia.org/wiki/Zstd), For file size above ' . Storage::human(APP_STORAGE_READ_BUFFER, 0) . ' compression is skipped even if it\'s enabled', true) ->param('encryption', true, new Boolean(true), 'Is encryption enabled? For file size above ' . Storage::human(APP_STORAGE_READ_BUFFER, 0) . ' encryption is skipped even if it\'s enabled', true) ->param('antivirus', true, new Boolean(true), 'Is virus scanning enabled? For file size above ' . Storage::human(APP_LIMIT_ANTIVIRUS, 0) . ' AntiVirus scanning is skipped even if it\'s enabled', true) ->inject('response') @@ -237,7 +237,7 @@ App::put('/v1/storage/buckets/:bucketId') ->param('enabled', true, new Boolean(true), 'Is bucket enabled?', true) ->param('maximumFileSize', null, new Range(1, (int) App::getEnv('_APP_STORAGE_LIMIT', 0)), 'Maximum file size allowed in bytes. Maximum allowed value is ' . Storage::human((int)App::getEnv('_APP_STORAGE_LIMIT', 0), 0) . '. For self hosted version you can change the limit by changing _APP_STORAGE_LIMIT environment variable. [Learn more about storage environment variables](docs/environment-variables#storage)', true) ->param('allowedFileExtensions', [], new ArrayList(new Text(64), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Allowed file extensions. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' extensions are allowed, each 64 characters long.', true) - ->param('compression', 'none', new WhiteList([COMPRESSION_TYPE_NONE, COMPRESSION_TYPE_GZIP, COMPRESSION_TYPE_ZSTD]), 'Compression algorithm choosen for compression. Can be one of ' . COMPRESSION_TYPE_NONE . ', [' . COMPRESSION_TYPE_GZIP . '](https://en.wikipedia.org/wiki/Gzip), or [' . COMPRESSION_TYPE_ZSTD . '](https://en.wikipedia.org/wiki/Zstd), For file size above ' . Storage::human(APP_STORAGE_READ_BUFFER, 0) . ' compression is skipped even if it\'s enabled', true) + ->param('compression', COMPRESSION_TYPE_NONE, new WhiteList([COMPRESSION_TYPE_NONE, COMPRESSION_TYPE_GZIP, COMPRESSION_TYPE_ZSTD]), 'Compression algorithm choosen for compression. Can be one of ' . COMPRESSION_TYPE_NONE . ', [' . COMPRESSION_TYPE_GZIP . '](https://en.wikipedia.org/wiki/Gzip), or [' . COMPRESSION_TYPE_ZSTD . '](https://en.wikipedia.org/wiki/Zstd), For file size above ' . Storage::human(APP_STORAGE_READ_BUFFER, 0) . ' compression is skipped even if it\'s enabled', true) ->param('encryption', true, new Boolean(true), 'Is encryption enabled? For file size above ' . Storage::human(APP_STORAGE_READ_BUFFER, 0) . ' encryption is skipped even if it\'s enabled', true) ->param('antivirus', true, new Boolean(true), 'Is virus scanning enabled? For file size above ' . Storage::human(APP_LIMIT_ANTIVIRUS, 0) . ' AntiVirus scanning is skipped even if it\'s enabled', true) ->inject('response') @@ -509,14 +509,14 @@ App::post('/v1/storage/buckets/:bucketId/files') $mimeType = $deviceFiles->getFileMimeType($path); // Get mime-type before compression and encryption $data = ''; // Compression - $algorithm = $bucket->getAttribute('compression', 'none'); - if ($fileSize <= APP_STORAGE_READ_BUFFER && $algorithm != 'none') { + $algorithm = $bucket->getAttribute('compression', COMPRESSION_TYPE_NONE); + if ($fileSize <= APP_STORAGE_READ_BUFFER && $algorithm != COMPRESSION_TYPE_NONE) { $data = $deviceFiles->read($path); switch ($algorithm) { - case 'zstd': + case COMPRESSION_TYPE_ZSTD: $compressor = new Zstd(); break; - case 'gzip': + case COMPRESSION_TYPE_GZIP: default: $compressor = new GZIP(); break; From a1cb81abb6ff67ef88757edf4e2fd46b86135523 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Wed, 11 Jan 2023 21:49:15 +0000 Subject: [PATCH 10/11] Function default timeout example to 15s, so it doesn't look like a timestamp. --- src/Appwrite/Utopia/Response/Model/Func.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Response/Model/Func.php b/src/Appwrite/Utopia/Response/Model/Func.php index c7e69fff88..74cfb1e844 100644 --- a/src/Appwrite/Utopia/Response/Model/Func.php +++ b/src/Appwrite/Utopia/Response/Model/Func.php @@ -97,7 +97,7 @@ class Func extends Model 'type' => self::TYPE_INTEGER, 'description' => 'Function execution timeout in seconds.', 'default' => 15, - 'example' => 1592981237, + 'example' => 15, ]) ; } From 58c4c3da1e6a0229b380f98188faa53587fd1590 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 20 Jan 2023 09:52:11 +0000 Subject: [PATCH 11/11] feat: update changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 5103e39a11..a6fa76fff7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,7 @@ # Version 1.2.1 ## Bugs - Fix a few null safety warnings [#4654](https://github.com/appwrite/appwrite/pull/4654) +- Fix timestamp format in Realtime response [#4515](https://github.com/appwrite/appwrite/pull/4515) # Version 1.2.0 ## Features