versionData()['panel'] ?? 'error'; } /** * Get the latest version of the daemon from the CDN servers. */ public function getDaemon(): string { return $this->versionData()['wings'] ?? 'error'; } /** * Get the URL to the discord server. */ public function getDiscord(): string { return $this->versionData()['discord'] ?? 'https://pterodactyl.io/discord'; } /** * Get the URL for donations. */ public function getDonations(): string { return $this->versionData()['donations'] ?? 'https://github.com/sponsors/matthewpi'; } /** * Determine if the current version of the panel is the latest. */ public function isLatestPanel(): bool { $version = config()->string('app.version'); if ($version === 'canary') { return true; } return version_compare($version, $this->getPanel()) >= 0; } /** * Keeps the versioning cache up-to-date with the latest results from the CDN. * * @return SoftwareVersionData */ protected function versionData(): array { $this->result ??= $this->cacheVersionData(); return $this->result; } /** * @return SoftwareVersionData */ protected function cacheVersionData(): array { $cached = $this->cache->remember(self::VERSION_CACHE_KEY, CarbonImmutable::now()->addMinutes(config()->integer('pterodactyl.cdn.cache_time', 60)), function (): array { try { $response = $this->client->request('GET', config()->string('pterodactyl.cdn.url'), ['timeout' => 5, 'connect_timeout' => 2]); if ($response->getStatusCode() === 200) { $data = json_decode($response->getBody()->__toString(), true, flags: JSON_THROW_ON_ERROR); return is_array($data) ? $data : []; } throw new CdnVersionFetchingException; } catch (Exception) { return []; } }); return $this->normalizeVersionData($cached); } /** * @return SoftwareVersionData */ private function normalizeVersionData(mixed $value): array { if (! is_array($value)) { return []; } $normalized = []; foreach (['panel', 'wings', 'discord', 'donations'] as $key) { $item = $value[$key] ?? null; if (is_string($item)) { $normalized[$key] = $item; } } return $normalized; } }