diff --git a/app/app.php b/app/app.php index e92660b5a0..53adb75c63 100644 --- a/app/app.php +++ b/app/app.php @@ -50,7 +50,7 @@ $clients = \array_unique(\array_merge($clientsConsole, \array_map(function ($nod return false; })))); -$utopia->init(function () use ($utopia, $request, $response, &$user, $project, $console, $webhook, $mail, $audit, $usage, $clients) { +$utopia->init(function () use ($utopia, $request, $response, &$user, $project, $console, $webhook, $audit, $usage, $clients) { $route = $utopia->match($request); diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index 90f8ac34c8..08940b1196 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -18,21 +18,16 @@ use BaconQrCode\Writer; use Utopia\Config\Config; use Utopia\Validator\HexColor; -$types = [ - 'browsers' => include __DIR__.'/../../config/avatars/browsers.php', - 'credit-cards' => include __DIR__.'/../../config/avatars/credit-cards.php', - 'flags' => include __DIR__.'/../../config/avatars/flags.php', -]; - -$avatarCallback = function ($type, $code, $width, $height, $quality) use ($types, $response) { +$avatarCallback = function ($type, $code, $width, $height, $quality) use ($response) { $code = \strtolower($code); $type = \strtolower($type); + $set = Config::getParam('avatar-'.$type, []); - if (!\array_key_exists($type, $types)) { + if (empty($set)) { throw new Exception('Avatar set not found', 404); } - if (!\array_key_exists($code, $types[$type])) { + if (!\array_key_exists($code, $set)) { throw new Exception('Avatar not found', 404); } @@ -43,7 +38,7 @@ $avatarCallback = function ($type, $code, $width, $height, $quality) use ($types $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); - $path = $types[$type][$code]; + $path = $set[$code]; $type = 'png'; if (!\is_readable($path)) { @@ -89,7 +84,7 @@ $avatarCallback = function ($type, $code, $width, $height, $quality) use ($types $utopia->get('/v1/avatars/credit-cards/:code') ->desc('Get Credit Card Icon') ->groups(['api', 'avatars']) - ->param('code', '', function () use ($types) { return new WhiteList(\array_keys($types['credit-cards'])); }, 'Credit Card Code. Possible values: '.\implode(', ', \array_keys($types['credit-cards'])).'.') + ->param('code', '', function () { return new WhiteList(\array_keys(Config::getParam('avatar-credit-cards'))); }, 'Credit Card Code. Possible values: '.\implode(', ', \array_keys(Config::getParam('avatar-credit-cards'))).'.') ->param('width', 100, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('height', 100, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('quality', 100, function () { return new Range(0, 100); }, 'Image quality. Pass an integer between 0 to 100. Defaults to 100.', true) @@ -106,7 +101,7 @@ $utopia->get('/v1/avatars/credit-cards/:code') $utopia->get('/v1/avatars/browsers/:code') ->desc('Get Browser Icon') ->groups(['api', 'avatars']) - ->param('code', '', function () use ($types) { return new WhiteList(\array_keys($types['browsers'])); }, 'Browser Code.') + ->param('code', '', function () { return new WhiteList(\array_keys(Config::getParam('avatar-browsers'))); }, 'Browser Code.') ->param('width', 100, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('height', 100, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('quality', 100, function () { return new Range(0, 100); }, 'Image quality. Pass an integer between 0 to 100. Defaults to 100.', true) @@ -123,7 +118,7 @@ $utopia->get('/v1/avatars/browsers/:code') $utopia->get('/v1/avatars/flags/:code') ->desc('Get Country Flag') ->groups(['api', 'avatars']) - ->param('code', '', function () use ($types) { return new WhiteList(\array_keys($types['flags'])); }, 'Country Code. ISO Alpha-2 country code format.') + ->param('code', '', function () { return new WhiteList(\array_keys(Config::getParam('avatar-flags'))); }, 'Country Code. ISO Alpha-2 country code format.') ->param('width', 100, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('height', 100, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('quality', 100, function () { return new Range(0, 100); }, 'Image quality. Pass an integer between 0 to 100. Defaults to 100.', true) diff --git a/app/init.php b/app/init.php index 4512061d2d..1b340d23ac 100644 --- a/app/init.php +++ b/app/init.php @@ -64,6 +64,9 @@ Config::load('locales', __DIR__.'/../app/config/locales.php'); Config::load('collections', __DIR__.'/../app/config/collections.php'); Config::load('roles', __DIR__.'/../app/config/roles.php'); // User roles and scopes Config::load('services', __DIR__.'/../app/config/services.php'); // List of services +Config::load('avatar-browsers', __DIR__.'/../app/config/avatars/browsers.php'); +Config::load('avatar-credit-cards', __DIR__.'/../app/config/avatars/credit-cards.php'); +Config::load('avatar-flags', __DIR__.'/../app/config/avatars/flags.php'); Config::setParam('env', $utopia->getMode()); Config::setParam('domain', $request->getServer('HTTP_HOST', ''));