mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 09:54:44 +02:00
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:
parent
ce1163d387
commit
0da184c56e
@ -1,7 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Exceptions\Service\Helper;
|
|
||||||
|
|
||||||
class CdnVersionFetchingException extends \Exception
|
|
||||||
{
|
|
||||||
}
|
|
@ -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 () {
|
||||||
try {
|
$versionData = [];
|
||||||
$response = $this->client->request('GET', config('panel.cdn.url'));
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
$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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user