2018-08-30 05:37:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
use Illuminate\Contracts\Cache\Repository as Cache;
|
|
|
|
use Illuminate\Log\Logger;
|
2020-12-22 20:11:22 +00:00
|
|
|
use Throwable;
|
2018-08-30 05:37:03 +00:00
|
|
|
|
|
|
|
class ApplicationInformationService
|
|
|
|
{
|
2018-08-30 05:42:47 +00:00
|
|
|
private const CACHE_KEY = 'latestKoelVersion';
|
|
|
|
|
2021-06-05 10:47:56 +00:00
|
|
|
private Client $client;
|
|
|
|
private Cache $cache;
|
|
|
|
private Logger $logger;
|
2018-08-30 05:37:03 +00:00
|
|
|
|
|
|
|
public function __construct(Client $client, Cache $cache, Logger $logger)
|
|
|
|
{
|
|
|
|
$this->client = $client;
|
|
|
|
$this->cache = $cache;
|
|
|
|
$this->logger = $logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the latest version number of Koel from GitHub.
|
|
|
|
*/
|
2018-08-30 05:37:24 +00:00
|
|
|
public function getLatestVersionNumber(): string
|
|
|
|
{
|
2021-06-05 10:47:56 +00:00
|
|
|
return $this->cache->remember(self::CACHE_KEY, now()->addDay(), function (): string {
|
2018-08-30 05:37:03 +00:00
|
|
|
try {
|
2021-06-05 10:47:56 +00:00
|
|
|
return json_decode($this->client->get('https://api.github.com/repos/koel/koel/tags')->getBody())[0]
|
|
|
|
->name;
|
2020-12-22 20:11:22 +00:00
|
|
|
} catch (Throwable $e) {
|
2018-08-30 05:37:03 +00:00
|
|
|
$this->logger->error($e);
|
|
|
|
|
2021-01-10 22:17:37 +00:00
|
|
|
return koel_version();
|
2018-08-30 05:37:03 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|