diff --git a/.env b/.env index 9948d4d22..f8777509a 100644 --- a/.env +++ b/.env @@ -18,5 +18,6 @@ _APP_STATSD_HOST=telegraf _APP_STATSD_PORT=8125 _APP_SMTP_HOST=maildev _APP_SMTP_PORT=25 +_APP_STORAGE_LIMIT=100000000 _APP_FUNCTIONS_TIMEOUT=900 _APP_FUNCTIONS_CONTAINERS=10 \ No newline at end of file diff --git a/CHANGES.md b/CHANGES.md index cbd190996..22026bf2a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -20,6 +20,7 @@ - Optimised function execution by using fully-qualified function calls - Added support for boolean 'true' and 'false' in query strings alongside 1 and 0 - Added pagination for projects list on the console home page. +- Updated storage calculation to match IEC standards - New and consistent response format for all API object + new response examples in the docs - Removed user roles attribute from user object (can be fetched from /v1/teams/memberships) ** - Removed type attribute from session object response (used only internally) diff --git a/Dockerfile b/Dockerfile index 2d3eeae80..9c2b3a214 100755 --- a/Dockerfile +++ b/Dockerfile @@ -77,7 +77,7 @@ ENV TZ=Asia/Tel_Aviv \ _APP_OPTIONS_ABUSE=enabled \ _APP_OPTIONS_FORCE_HTTPS=disabled \ _APP_OPENSSL_KEY_V1=your-secret-key \ - _APP_STORAGE_LIMIT=104857600 \ + _APP_STORAGE_LIMIT=100000000 \ _APP_STORAGE_ANTIVIRUS=enabled \ _APP_REDIS_HOST=redis \ _APP_REDIS_PORT=6379 \ diff --git a/Dockerfile.alpine b/Dockerfile.alpine index e56afcf4b..e60b97585 100755 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -77,7 +77,7 @@ ENV TZ=Asia/Tel_Aviv \ _APP_OPTIONS_ABUSE=enabled \ _APP_OPTIONS_FORCE_HTTPS=disabled \ _APP_OPENSSL_KEY_V1=your-secret-key \ - _APP_STORAGE_LIMIT=104857600 \ + _APP_STORAGE_LIMIT=100000000 \ _APP_STORAGE_ANTIVIRUS=enabled \ _APP_REDIS_HOST=redis \ _APP_REDIS_PORT=6379 \ diff --git a/Dockerfile.nginx b/Dockerfile.nginx index 31d96d8b0..3bd88a7d3 100644 --- a/Dockerfile.nginx +++ b/Dockerfile.nginx @@ -60,7 +60,7 @@ ENV TZ=Asia/Tel_Aviv \ _APP_OPTIONS_ABUSE=enabled \ _APP_OPTIONS_FORCE_HTTPS=disabled \ _APP_OPENSSL_KEY_V1=your-secret-key \ - _APP_STORAGE_LIMIT=104857600 \ + _APP_STORAGE_LIMIT=100000000 \ _APP_STORAGE_ANTIVIRUS=enabled \ _APP_REDIS_HOST=redis \ _APP_REDIS_PORT=6379 \ diff --git a/Dockerfile.php8 b/Dockerfile.php8 index bcf58ccbf..2cc74ef76 100755 --- a/Dockerfile.php8 +++ b/Dockerfile.php8 @@ -77,7 +77,7 @@ ENV TZ=Asia/Tel_Aviv \ _APP_OPTIONS_ABUSE=enabled \ _APP_OPTIONS_FORCE_HTTPS=disabled \ _APP_OPENSSL_KEY_V1=your-secret-key \ - _APP_STORAGE_LIMIT=104857600 \ + _APP_STORAGE_LIMIT=100000000 \ _APP_STORAGE_ANTIVIRUS=enabled \ _APP_REDIS_HOST=redis \ _APP_REDIS_PORT=6379 \ diff --git a/Dockerfile.swoole b/Dockerfile.swoole index 5fd69f865..a2573e0fc 100755 --- a/Dockerfile.swoole +++ b/Dockerfile.swoole @@ -77,7 +77,7 @@ ENV TZ=Asia/Tel_Aviv \ _APP_OPTIONS_ABUSE=enabled \ _APP_OPTIONS_FORCE_HTTPS=disabled \ _APP_OPENSSL_KEY_V1=your-secret-key \ - _APP_STORAGE_LIMIT=104857600 \ + _APP_STORAGE_LIMIT=100000000 \ _APP_STORAGE_ANTIVIRUS=enabled \ _APP_REDIS_HOST=redis \ _APP_REDIS_PORT=6379 \ diff --git a/app/server.php b/app/server.php index af3c0d41f..fd4f260a4 100644 --- a/app/server.php +++ b/app/server.php @@ -23,6 +23,8 @@ sleep(2); $http = new Server("0.0.0.0", 80); +$payloadSize = max(4000000 /* 4mb */, App::getEnv('_APP_STORAGE_LIMIT', 100000000)); + $http ->set([ 'open_http2_protocol' => true, @@ -31,7 +33,7 @@ $http 'timeout' => 7, 'http_compression' => true, 'http_compression_level' => 6, - 'package_max_length' => 1000000 * 150, // 150MB + 'package_max_length' => $payloadSize, ]) ; @@ -47,8 +49,8 @@ $http->on('AfterReload', function($serv, $workerId) { Console::success('Reload completed...'); }); -$http->on('start', function (Server $http) { - Console::success('Server started succefully'); +$http->on('start', function (Server $http) use ($payloadSize) { + Console::success('Server started succefully (max payload is '.$payloadSize.' bytes)'); Console::info("Master pid {$http->master_pid}, manager pid {$http->manager_pid}"); diff --git a/docker-compose.yml b/docker-compose.yml index 8aedd281a..484f73b42 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -80,6 +80,7 @@ services: - _APP_DB_PASS - _APP_INFLUXDB_HOST - _APP_INFLUXDB_PORT + - _APP_STORAGE_LIMIT - _APP_FUNCTIONS_TIMEOUT - _APP_FUNCTIONS_CONTAINERS diff --git a/src/Appwrite/Storage/Storage.php b/src/Appwrite/Storage/Storage.php index 0395ab2ed..30718dc0a 100644 --- a/src/Appwrite/Storage/Storage.php +++ b/src/Appwrite/Storage/Storage.php @@ -67,24 +67,45 @@ class Storage /** * Human readable data size format from bytes input. * - * As published on https://gist.github.com/liunian/9338301 (first comment) + * Based on: https://stackoverflow.com/a/38659168/2299554 * * @param int $bytes * @param int $decimals + * @param string $system * * @return string */ - public static function human($bytes, $decimals = 2) + public static function human(int $bytes, $decimals = 2, $system = 'metric') { - $units = array('B','kB','MB','GB','TB','PB','EB','ZB','YB'); - $step = 1024; - $i = 0; + $mod = ($system === 'binary') ? 1024 : 1000; - while (($bytes / $step) > 0.9) { - $bytes = $bytes / $step; - ++$i; - } + $units = array( + 'binary' => array( + 'B', + 'KiB', + 'MiB', + 'GiB', + 'TiB', + 'PiB', + 'EiB', + 'ZiB', + 'YiB', + ), + 'metric' => array( + 'B', + 'kB', + 'MB', + 'GB', + 'TB', + 'PB', + 'EB', + 'ZB', + 'YB', + ), + ); - return \round($bytes, $decimals).$units[$i]; + $factor = floor((strlen($bytes) - 1) / 3); + + return sprintf("%.{$decimals}f%s", $bytes / pow($mod, $factor), $units[$system][$factor]); } -} +} \ No newline at end of file diff --git a/src/Appwrite/Storage/Validator/FileSize.php b/src/Appwrite/Storage/Validator/FileSize.php index b4aab0c57..1f66e3f02 100644 --- a/src/Appwrite/Storage/Validator/FileSize.php +++ b/src/Appwrite/Storage/Validator/FileSize.php @@ -12,6 +12,8 @@ class FileSize extends Validator protected $max; /** + * Max size in bytes + * * @param int $max */ public function __construct($max)