diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index e3b56cf588..198f379171 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -16,9 +16,9 @@ use Utopia\Validator\Boolean; use Utopia\Validator\HexColor; use Utopia\Validator\Range; use Utopia\Validator\Text; -use Utopia\Validator\WhiteList; +use Utopia\Validator\WhiteList; -$avatarCallback = function ($type, $code, $width, $height, $quality, Response $response) { +$avatarCallback = function (string $type, string $code, int $width, int $height, int $quality, Response $response) { $code = \strtolower($code); $type = \strtolower($type); @@ -38,7 +38,7 @@ $avatarCallback = function ($type, $code, $width, $height, $quality, Response $r $output = 'png'; $date = \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT'; // 45 days cache - $key = \md5('/v1/avatars/'.$type.'/:code-' . $code . $width . $height . $quality . $output); + $key = \md5('/v1/avatars/' . $type . '/:code-' . $code . $width . $height . $quality . $output); $path = $set[$code]; $type = 'png'; @@ -56,8 +56,7 @@ $avatarCallback = function ($type, $code, $width, $height, $quality, Response $r ->setContentType('image/png') ->addHeader('Expires', $date) ->addHeader('X-Appwrite-Cache', 'hit') - ->send($data) - ; + ->send($data); } $image = new Image(\file_get_contents($path)); @@ -95,7 +94,7 @@ App::get('/v1/avatars/credit-cards/:code') ->param('height', 100, new Range(0, 2000), 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('quality', 100, new Range(0, 100), 'Image quality. Pass an integer between 0 to 100. Defaults to 100.', true) ->inject('response') - ->action(fn($code, $width, $height, $quality, $response) => $avatarCallback('credit-cards', $code, $width, $height, $quality, $response)); + ->action(fn (string $code, int $width, int $height, int $quality, Response $response) => $avatarCallback('credit-cards', $code, $width, $height, $quality, $response)); App::get('/v1/avatars/browsers/:code') ->desc('Get Browser Icon') @@ -113,7 +112,7 @@ App::get('/v1/avatars/browsers/:code') ->param('height', 100, new Range(0, 2000), 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('quality', 100, new Range(0, 100), 'Image quality. Pass an integer between 0 to 100. Defaults to 100.', true) ->inject('response') - ->action(fn($code, $width, $height, $quality, $response) => $avatarCallback('browsers', $code, $width, $height, $quality, $response)); + ->action(fn (string $code, int $width, int $height, int $quality, Response $response) => $avatarCallback('browsers', $code, $width, $height, $quality, $response)); App::get('/v1/avatars/flags/:code') ->desc('Get Country Flag') @@ -131,7 +130,7 @@ App::get('/v1/avatars/flags/:code') ->param('height', 100, new Range(0, 2000), 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('quality', 100, new Range(0, 100), 'Image quality. Pass an integer between 0 to 100. Defaults to 100.', true) ->inject('response') - ->action(fn($code, $width, $height, $quality, $response) => $avatarCallback('flags', $code, $width, $height, $quality, $response)); + ->action(fn (string $code, int $width, int $height, int $quality, Response $response) => $avatarCallback('flags', $code, $width, $height, $quality, $response)); App::get('/v1/avatars/image') ->desc('Get Image from URL') @@ -148,7 +147,7 @@ App::get('/v1/avatars/image') ->param('width', 400, new Range(0, 2000), 'Resize preview image width, Pass an integer between 0 to 2000.', true) ->param('height', 400, new Range(0, 2000), 'Resize preview image height, Pass an integer between 0 to 2000.', true) ->inject('response') - ->action(function ($url, $width, $height, Response $response) { + ->action(function (string $url, int $width, int $height, Response $response) { $quality = 80; $output = 'png'; @@ -163,8 +162,7 @@ App::get('/v1/avatars/image') ->setContentType('image/png') ->addHeader('Expires', $date) ->addHeader('X-Appwrite-Cache', 'hit') - ->send($data) - ; + ->send($data); } if (!\extension_loaded('imagick')) { @@ -179,7 +177,7 @@ App::get('/v1/avatars/image') try { $image = new Image($fetch); - } catch (\Exception$exception) { + } catch (\Exception $exception) { throw new Exception('Unable to parse image', 500, Exception::GENERAL_SERVER_ERROR); } @@ -195,8 +193,7 @@ App::get('/v1/avatars/image') ->setContentType('image/png') ->addHeader('Expires', $date) ->addHeader('X-Appwrite-Cache', 'miss') - ->send($data); - ; + ->send($data);; unset($image); }); @@ -214,7 +211,7 @@ App::get('/v1/avatars/favicon') ->label('sdk.response.type', Response::CONTENT_TYPE_IMAGE) ->param('url', '', new URL(['http', 'https']), 'Website URL which you want to fetch the favicon from.') ->inject('response') - ->action(function ($url, Response $response) { + ->action(function (string $url, Response $response) { $width = 56; $height = 56; @@ -231,8 +228,7 @@ App::get('/v1/avatars/favicon') ->setContentType('image/png') ->addHeader('Expires', $date) ->addHeader('X-Appwrite-Cache', 'hit') - ->send($data) - ; + ->send($data); } if (!\extension_loaded('imagick')) { @@ -246,7 +242,8 @@ App::get('/v1/avatars/favicon') CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 3, CURLOPT_URL => $url, - CURLOPT_USERAGENT => \sprintf(APP_USERAGENT, + CURLOPT_USERAGENT => \sprintf( + APP_USERAGENT, App::getEnv('_APP_VERSION', 'UNKNOWN'), App::getEnv('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS', APP_EMAIL_SECURITY) ), @@ -324,8 +321,7 @@ App::get('/v1/avatars/favicon') ->setContentType('image/x-icon') ->addHeader('Expires', $date) ->addHeader('X-Appwrite-Cache', 'miss') - ->send($data) - ; + ->send($data); } $fetch = @\file_get_contents($outputHref, false); @@ -369,7 +365,7 @@ App::get('/v1/avatars/qr') ->param('margin', 1, new Range(0, 10), 'Margin from edge. Pass an integer between 0 to 10. Defaults to 1.', true) ->param('download', false, new Boolean(true), 'Return resulting image with \'Content-Disposition: attachment \' headers for the browser to start downloading it. Pass 0 for no header, or 1 for otherwise. Default value is set to 0.', true) ->inject('response') - ->action(function ($text, $size, $margin, $download, Response $response) { + ->action(function (string $text, int $size, int $margin, bool $download, Response $response) { $download = ($download === '1' || $download === 'true' || $download === 1 || $download === true); $options = new QROptions([ @@ -391,8 +387,7 @@ App::get('/v1/avatars/qr') $response ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache ->setContentType('image/png') - ->send($image->output('png', 9)) - ; + ->send($image->output('png', 9)); }); App::get('/v1/avatars/initials') @@ -413,7 +408,7 @@ App::get('/v1/avatars/initials') ->param('background', '', new HexColor(), 'Changes background color. By default a random color will be picked and stay will persistent to the given name.', true) ->inject('response') ->inject('user') - ->action(function ($name, $width, $height, $color, $background, Response $response, Document $user) { + ->action(function (string $name, int $width, int $height, string $color, string $background, Response $response, Document $user) { $themes = [ ['color' => '#27005e', 'background' => '#e1d2f6'], // VIOLET @@ -433,8 +428,8 @@ App::get('/v1/avatars/initials') $name = (!empty($name)) ? $name : $user->getAttribute('name', $user->getAttribute('email', '')); $words = \explode(' ', \strtoupper($name)); // if there is no space, try to split by `_` underscore - $words = (count($words) == 1 ) ? \explode('_', \strtoupper($name)) : $words; - + $words = (count($words) == 1) ? \explode('_', \strtoupper($name)) : $words; + $initials = null; $code = 0; @@ -473,6 +468,5 @@ App::get('/v1/avatars/initials') $response ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache ->setContentType('image/png') - ->send($image->getImageBlob()) - ; + ->send($image->getImageBlob()); }); diff --git a/app/controllers/api/locale.php b/app/controllers/api/locale.php index bd3891a893..cf7c49566e 100644 --- a/app/controllers/api/locale.php +++ b/app/controllers/api/locale.php @@ -24,7 +24,6 @@ App::get('/v1/locale') ->inject('locale') ->inject('geodb') ->action(function (Request $request, Response $response, Locale $locale, Reader $geodb) { - $eu = Config::getParam('locale-eu'); $currencies = Config::getParam('locale-currencies'); $output = []; @@ -39,8 +38,8 @@ App::get('/v1/locale') if ($record) { $output['countryCode'] = $record['country']['iso_code']; - $output['country'] = $locale->getText('countries.'.strtolower($record['country']['iso_code']), $locale->getText('locale.country.unknown')); - $output['continent'] = $locale->getText('continents.'.strtolower($record['continent']['code']), $locale->getText('locale.country.unknown')); + $output['country'] = $locale->getText('countries.' . strtolower($record['country']['iso_code']), $locale->getText('locale.country.unknown')); + $output['continent'] = $locale->getText('continents.' . strtolower($record['continent']['code']), $locale->getText('locale.country.unknown')); $output['continent'] = (isset($continents[$record['continent']['code']])) ? $continents[$record['continent']['code']] : $locale->getText('locale.country.unknown'); $output['continentCode'] = $record['continent']['code']; $output['eu'] = (\in_array($record['country']['iso_code'], $eu)) ? true : false; @@ -62,8 +61,8 @@ App::get('/v1/locale') } $response - ->addHeader('Cache-Control', 'public, max-age='.$time) - ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + $time).' GMT') // 45 days cache + ->addHeader('Cache-Control', 'public, max-age=' . $time) + ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + $time) . ' GMT') // 45 days cache ; $response->dynamic(new Document($output), Response::MODEL_LOCALE); }); @@ -82,13 +81,12 @@ App::get('/v1/locale/countries') ->inject('response') ->inject('locale') ->action(function (Response $response, Locale $locale) { - $list = Config::getParam('locale-countries'); /* @var $list array */ $output = []; foreach ($list as $value) { $output[] = new Document([ - 'name' => $locale->getText('countries.'.strtolower($value)), + 'name' => $locale->getText('countries.' . strtolower($value)), 'code' => $value, ]); } @@ -114,14 +112,13 @@ App::get('/v1/locale/countries/eu') ->inject('response') ->inject('locale') ->action(function (Response $response, Locale $locale) { - $eu = Config::getParam('locale-eu'); $output = []; foreach ($eu as $code) { - if ($locale->getText('countries.'.strtolower($code), false) !== false) { + if ($locale->getText('countries.' . strtolower($code), false) !== false) { $output[] = new Document([ - 'name' => $locale->getText('countries.'.strtolower($code)), + 'name' => $locale->getText('countries.' . strtolower($code)), 'code' => $code, ]); } @@ -148,18 +145,17 @@ App::get('/v1/locale/countries/phones') ->inject('response') ->inject('locale') ->action(function (Response $response, Locale $locale) { - $list = Config::getParam('locale-phones'); /* @var $list array */ $output = []; \asort($list); foreach ($list as $code => $name) { - if ($locale->getText('countries.'.strtolower($code), false) !== false) { + if ($locale->getText('countries.' . strtolower($code), false) !== false) { $output[] = new Document([ - 'code' => '+'.$list[$code], + 'code' => '+' . $list[$code], 'countryCode' => $code, - 'countryName' => $locale->getText('countries.'.strtolower($code)), + 'countryName' => $locale->getText('countries.' . strtolower($code)), ]); } } @@ -181,12 +177,11 @@ App::get('/v1/locale/continents') ->inject('response') ->inject('locale') ->action(function (Response $response, Locale $locale) { + $list = Config::getParam('locale-continents'); - $list = Config::getParam('locale-continents'); /* @var $list array */ - - foreach ($list as $key => $value) { + foreach ($list as $value) { $output[] = new Document([ - 'name' => $locale->getText('continents.'.strtolower($value)), + 'name' => $locale->getText('continents.' . strtolower($value)), 'code' => $value, ]); } @@ -211,10 +206,9 @@ App::get('/v1/locale/currencies') ->label('sdk.response.model', Response::MODEL_CURRENCY_LIST) ->inject('response') ->action(function (Response $response) { - $list = Config::getParam('locale-currencies'); - $list = array_map(fn($node) => new Document($node), $list); + $list = array_map(fn ($node) => new Document($node), $list); $response->dynamic(new Document(['currencies' => $list, 'total' => \count($list)]), Response::MODEL_CURRENCY_LIST); }); @@ -233,10 +227,9 @@ App::get('/v1/locale/languages') ->label('sdk.response.model', Response::MODEL_LANGUAGE_LIST) ->inject('response') ->action(function (Response $response) { - $list = Config::getParam('locale-languages'); $list = array_map(fn ($node) => new Document($node), $list); $response->dynamic(new Document(['languages' => $list, 'total' => \count($list)]), Response::MODEL_LANGUAGE_LIST); - }); \ No newline at end of file + }); diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 8d047f2e21..9ad25bda69 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -159,7 +159,7 @@ App::get('/v1/storage/buckets') ->inject('usage') ->action(function (string $search, int $limit, int $offset, string $cursor, string $cursorDirection, string $orderType, Response $response, Database $dbForProject, Stats $usage) { - $queries = ($search) ? [new Query('name', Query::TYPE_SEARCH, $search)] : []; + $queries = ($search) ? [new Query('name', Query::TYPE_SEARCH, [$search])] : []; if (!empty($cursor)) { $cursorBucket = $dbForProject->getDocument('buckets', $cursor);