Path: blob/1.0-develop/app/Services/Helpers/SoftwareVersionService.php
10280 views
<?php12namespace Pterodactyl\Services\Helpers;34use GuzzleHttp\Client;5use Carbon\CarbonImmutable;6use Illuminate\Support\Arr;7use Illuminate\Contracts\Cache\Repository as CacheRepository;8use Pterodactyl\Exceptions\Service\Helper\CdnVersionFetchingException;910class SoftwareVersionService11{12public const VERSION_CACHE_KEY = 'pterodactyl:versioning_data';1314private static array $result;1516/**17* SoftwareVersionService constructor.18*/19public function __construct(20protected CacheRepository $cache,21protected Client $client,22) {23self::$result = $this->cacheVersionData();24}2526/**27* Get the latest version of the panel from the CDN servers.28*/29public function getPanel(): string30{31return Arr::get(self::$result, 'panel') ?? 'error';32}3334/**35* Get the latest version of the daemon from the CDN servers.36*/37public function getDaemon(): string38{39return Arr::get(self::$result, 'wings') ?? 'error';40}4142/**43* Get the URL to the discord server.44*/45public function getDiscord(): string46{47return Arr::get(self::$result, 'discord') ?? 'https://pterodactyl.io/discord';48}4950/**51* Get the URL for donations.52*/53public function getDonations(): string54{55return Arr::get(self::$result, 'donations') ?? 'https://github.com/sponsors/matthewpi';56}5758/**59* Determine if the current version of the panel is the latest.60*/61public function isLatestPanel(): bool62{63if (config('app.version') === 'canary') {64return true;65}6667return version_compare(config('app.version'), $this->getPanel()) >= 0;68}6970/**71* Determine if a passed daemon version string is the latest.72*/73public function isLatestDaemon(string $version): bool74{75if ($version === 'develop') {76return true;77}7879return version_compare($version, $this->getDaemon()) >= 0;80}8182/**83* Keeps the versioning cache up-to-date with the latest results from the CDN.84*/85protected function cacheVersionData(): array86{87return $this->cache->remember(self::VERSION_CACHE_KEY, CarbonImmutable::now()->addMinutes(config('pterodactyl.cdn.cache_time', 60)), function () {88try {89$response = $this->client->request('GET', config('pterodactyl.cdn.url'));9091if ($response->getStatusCode() === 200) {92return json_decode($response->getBody(), true);93}9495throw new CdnVersionFetchingException();96} catch (\Exception) {97return [];98}99});100}101}102103104