diff --git a/CHANGES.md b/CHANGES.md index d8e177b25..51239015f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,6 +21,8 @@ * Upgraded SMTP image to version 1.0.1 * File upload route (POST /v1/storage/files) now accept a single file per request * Added ENV vars to change system email sender name and address +* Usage for requests made by project admin in the console are not counted as API usage +* Added ENV var to change default file upload size limit. New default value is 100MB ## Bug Fixes diff --git a/Dockerfile b/Dockerfile index d7be8224a..47b8bad8a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -50,6 +50,7 @@ ENV TZ=Asia/Tel_Aviv \ _APP_EDITION=community \ _APP_OPTIONS_ABUSE=enabled \ _APP_OPENSSL_KEY_V1=your-secret-key \ + _APP_STORAGE_LIMIT=104857600 \ _APP_REDIS_HOST=redis \ _APP_REDIS_PORT=6379 \ _APP_DB_HOST=mariadb \ @@ -95,8 +96,9 @@ RUN \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -# Set Upload Limit -RUN echo "upload_max_filesize = 4M" > /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini +# Set Upload Limit (default to 100MB) +RUN echo "upload_max_filesize = ${_APP_STORAGE_LIMIT}" > /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini +RUN echo "post_max_size = ${_APP_STORAGE_LIMIT}" > /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini # Nginx Configuration (with self-signed ssl certificates) COPY ./docker/nginx.conf /etc/nginx/nginx.conf diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 04cf1dba7..ad1beef9a 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -172,9 +172,9 @@ $utopia->get('/v1/health/stats') 'version' => shell_exec('nginx -v 2>&1'), ], 'storage' => [ - 'used' => $device->human($device->getDirectorySize($device->getRoot().'/')), - 'partitionTotal' => $device->human($device->getPartitionTotalSpace()), - 'partitionFree' => $device->human($device->getPartitionFreeSpace()), + 'used' => Storage::human($device->getDirectorySize($device->getRoot().'/')), + 'partitionTotal' => Storage::human($device->getPartitionTotalSpace()), + 'partitionFree' => Storage::human($device->getPartitionFreeSpace()), ], 'cache' => [ 'uptime' => (isset($cacheStats['uptime_in_seconds'])) ? $cacheStats['uptime_in_seconds'] : 0, diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 58e949d0f..a166a9076 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -139,7 +139,7 @@ $utopia->post('/v1/storage/files') * Validators */ //$fileType = new FileType(array(FileType::FILE_TYPE_PNG, FileType::FILE_TYPE_GIF, FileType::FILE_TYPE_JPEG)); - $fileSize = new FileSize(2097152 * 2); // 4MB + $fileSize = new FileSize($request->getServer('_APP_STORAGE_LIMIT', 0)); $upload = new Upload(); if (empty($file)) { diff --git a/app/controllers/web/console.php b/app/controllers/web/console.php index a91cff909..dae9737e4 100644 --- a/app/controllers/web/console.php +++ b/app/controllers/web/console.php @@ -7,6 +7,7 @@ global $utopia, $response, $request, $layout, $version, $providers, $projectDB; use Utopia\View; use Database\Database; use Database\Validator\UID; +use Storage\Storage; $utopia->init(function () use ($layout, $utopia) { $layout @@ -203,9 +204,11 @@ $utopia->get('/console/storage') ->label('scope', 'console') ->action(function () use ($request, $layout) { $page = new View(__DIR__.'/../../views/console/storage/index.phtml'); - + $page - ->setParam('home', $request->getServer('_APP_HOME', '')) + ->setParam('home', $request->getServer('_APP_HOME', 0)) + ->setParam('fileLimit', $request->getServer('_APP_STORAGE_LIMIT', 0)) + ->setParam('fileLimitHuman', Storage::human($request->getServer('_APP_STORAGE_LIMIT', 0))) ; $layout diff --git a/app/views/console/storage/index.phtml b/app/views/console/storage/index.phtml index 420bd76f5..776950e9d 100644 --- a/app/views/console/storage/index.phtml +++ b/app/views/console/storage/index.phtml @@ -1,5 +1,7 @@ getParam('home', ''); +$fileLimit = $this->getParam('fileLimit', 0); +$fileLimitHuman = $this->getParam('fileLimitHuman', 0); ?>

@@ -29,8 +31,10 @@ $home = $this->getParam('home', ''); data-failure-param-alert-classname="error"> - - + + + +
(Max file size allowed: )
diff --git a/docs/tutorials/environment-variables.md b/docs/tutorials/environment-variables.md index c181d99a3..99ca4d8d8 100644 --- a/docs/tutorials/environment-variables.md +++ b/docs/tutorials/environment-variables.md @@ -16,6 +16,10 @@ Allows you to disable abuse checks and API rate limiting. By default, set to 'en This is your server private secret key that is used to encrypt all sensitive data on your server. Appwrite server encrypts all secret data on your server like webhooks, HTTP passwords, user sessions, and storage files. The var is not set by default, if you wish to take advantage of Appwrite encryption capabilities you should change it and make sure to keep it a secret. +### _APP_STORAGE_LIMIT + +Maximun file size allowed for file upload. The deafult value is 100MB limitation. You should pass your size limit value in bytes. + ### _APP_CONSOLE_WHITELIST_EMAILS This option is very useful for small teams or sole developers. To enable it, pass a list of allowed email addresses separated by a comma. diff --git a/src/Storage/Device.php b/src/Storage/Device.php index facfcdd40..0d3d976e0 100644 --- a/src/Storage/Device.php +++ b/src/Storage/Device.php @@ -163,28 +163,4 @@ abstract class Device * @return float */ abstract public function getPartitionTotalSpace():float; - - /** - * Human readable data size format from bytes input. - * - * As published on https://gist.github.com/liunian/9338301 (first comment) - * - * @param int $bytes - * @param int $decimals - * - * @return string - */ - public function human($bytes, $decimals = 2) - { - $units = array('B','kB','MB','GB','TB','PB','EB','ZB','YB'); - $step = 1024; - $i = 0; - - while (($bytes / $step) > 0.9) { - $bytes = $bytes / $step; - ++$i; - } - - return round($bytes, $decimals).$units[$i]; - } } diff --git a/src/Storage/Storage.php b/src/Storage/Storage.php index b5a7b9f30..bbb1f76e5 100644 --- a/src/Storage/Storage.php +++ b/src/Storage/Storage.php @@ -67,4 +67,28 @@ class Storage { return (bool) array_key_exists($name, self::$devices); } + + /** + * Human readable data size format from bytes input. + * + * As published on https://gist.github.com/liunian/9338301 (first comment) + * + * @param int $bytes + * @param int $decimals + * + * @return string + */ + static public function human($bytes, $decimals = 2) + { + $units = array('B','kB','MB','GB','TB','PB','EB','ZB','YB'); + $step = 1024; + $i = 0; + + while (($bytes / $step) > 0.9) { + $bytes = $bytes / $step; + ++$i; + } + + return round($bytes, $decimals).$units[$i]; + } }