diff --git a/app/Services/Helpers/SoftwareVersionService.php b/app/Services/Helpers/SoftwareVersionService.php index b984271c9..9d54161e9 100644 --- a/app/Services/Helpers/SoftwareVersionService.php +++ b/app/Services/Helpers/SoftwareVersionService.php @@ -1,25 +1,22 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Pterodactyl\Services\Helpers; -use stdClass; use Exception; use GuzzleHttp\Client; use Cake\Chronos\Chronos; +use Illuminate\Support\Arr; use Illuminate\Contracts\Cache\Repository as CacheRepository; -use Illuminate\Contracts\Config\Repository as ConfigRepository; use Pterodactyl\Exceptions\Service\Helper\CdnVersionFetchingException; class SoftwareVersionService { - const VERSION_CACHE_KEY = 'pterodactyl:versions'; + const VERSION_CACHE_KEY = 'pterodactyl:versioning_data'; + + /** + * @var array + */ + private static $result; /** * @var \Illuminate\Contracts\Cache\Repository @@ -31,28 +28,20 @@ class SoftwareVersionService */ protected $client; - /** - * @var \Illuminate\Contracts\Config\Repository - */ - protected $config; - /** * SoftwareVersionService constructor. * * @param \Illuminate\Contracts\Cache\Repository $cache * @param \GuzzleHttp\Client $client - * @param \Illuminate\Contracts\Config\Repository $config */ public function __construct( CacheRepository $cache, - Client $client, - ConfigRepository $config + Client $client ) { $this->cache = $cache; $this->client = $client; - $this->config = $config; - $this->cacheVersionData(); + self::$result = $this->cacheVersionData(); } /** @@ -62,7 +51,7 @@ class SoftwareVersionService */ public function getPanel() { - return object_get($this->cache->get(self::VERSION_CACHE_KEY), 'panel', 'error'); + return Arr::get(self::$result, 'panel') ?? 'error'; } /** @@ -72,7 +61,7 @@ class SoftwareVersionService */ public function getDaemon() { - return object_get($this->cache->get(self::VERSION_CACHE_KEY), 'daemon', 'error'); + return Arr::get(self::$result, 'daemon') ?? 'error'; } /** @@ -82,7 +71,17 @@ class SoftwareVersionService */ public function getDiscord() { - return object_get($this->cache->get(self::VERSION_CACHE_KEY), 'discord', 'https://pterodactyl.io/discord'); + return Arr::get(self::$result, 'discord') ?? 'https://pterodactyl.io/discord'; + } + + /** + * Get the URL for donations. + * + * @return string + */ + public function getDonations() + { + return Arr::get(self::$result, 'donations') ?? 'https://paypal.me/PterodactylSoftware'; } /** @@ -92,11 +91,11 @@ class SoftwareVersionService */ public function isLatestPanel() { - if ($this->config->get('app.version') === 'canary') { + if (config()->get('app.version') === 'canary') { return true; } - return version_compare($this->config->get('app.version'), $this->getPanel()) >= 0; + return version_compare(config()->get('app.version'), $this->getPanel()) >= 0; } /** @@ -116,20 +115,22 @@ class SoftwareVersionService /** * Keeps the versioning cache up-to-date with the latest results from the CDN. + * + * @return array */ protected function cacheVersionData() { - $this->cache->remember(self::VERSION_CACHE_KEY, Chronos::now()->addMinutes(config('pterodactyl.cdn.cache_time')), function () { + return $this->cache->remember(self::VERSION_CACHE_KEY, Chronos::now()->addMinutes(config()->get('pterodactyl.cdn.cache_time', 60)), function () { try { - $response = $this->client->request('GET', $this->config->get('pterodactyl.cdn.url')); + $response = $this->client->request('GET', config()->get('pterodactyl.cdn.url')); if ($response->getStatusCode() === 200) { - return json_decode($response->getBody()); + return json_decode($response->getBody(), true); } throw new CdnVersionFetchingException; } catch (Exception $exception) { - return new stdClass(); + return []; } }); } diff --git a/resources/views/admin/index.blade.php b/resources/views/admin/index.blade.php index 9e9690f8e..6c1364a71 100644 --- a/resources/views/admin/index.blade.php +++ b/resources/views/admin/index.blade.php @@ -45,14 +45,14 @@
- +
 
- +
- +
@endsection