Get latest Panel & Wings version from github api (#379)

* get latest panel % wings version from github api

* fix tests

* remove unused CdnVersionFetchingException
This commit is contained in:
Boy132 2024-06-13 08:23:45 +02:00 committed by GitHub
parent ce1163d387
commit 0da184c56e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 15 deletions

View File

@ -1,7 +0,0 @@
<?php
namespace App\Exceptions\Service\Helper;
class CdnVersionFetchingException extends \Exception
{
}

View File

@ -2,12 +2,11 @@
namespace App\Services\Helpers; namespace App\Services\Helpers;
use Exception;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Carbon\CarbonImmutable; use Carbon\CarbonImmutable;
use GuzzleHttp\Exception\ClientException;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Contracts\Cache\Repository as CacheRepository; use Illuminate\Contracts\Cache\Repository as CacheRepository;
use App\Exceptions\Service\Helper\CdnVersionFetchingException;
class SoftwareVersionService class SoftwareVersionService
{ {
@ -87,17 +86,27 @@ class SoftwareVersionService
protected function cacheVersionData(): array protected function cacheVersionData(): array
{ {
return $this->cache->remember(self::VERSION_CACHE_KEY, CarbonImmutable::now()->addMinutes(config('panel.cdn.cache_time', 60)), function () { return $this->cache->remember(self::VERSION_CACHE_KEY, CarbonImmutable::now()->addMinutes(config('panel.cdn.cache_time', 60)), function () {
$versionData = [];
try { try {
$response = $this->client->request('GET', config('panel.cdn.url')); $response = $this->client->request('GET', 'https://api.github.com/repos/pelican-dev/panel/releases/latest');
if ($response->getStatusCode() === 200) { if ($response->getStatusCode() === 200) {
return json_decode($response->getBody(), true); $panelData = json_decode($response->getBody(), true);
$versionData['panel'] = trim($panelData['tag_name'], 'v');
} }
throw new CdnVersionFetchingException(); $response = $this->client->request('GET', 'https://api.github.com/repos/pelican-dev/wings/releases/latest');
} catch (Exception) { if ($response->getStatusCode() === 200) {
return []; $wingsData = json_decode($response->getBody(), true);
$versionData['daemon'] = trim($wingsData['tag_name'], 'v');
} }
} catch (ClientException $e) {
}
$versionData['discord'] = 'https://pelican.dev/discord';
$versionData['donate'] = 'https://pelican.dev/donate';
return $versionData;
}); });
} }