mirror of https://github.com/pixelfed/pixelfed
Add Software Update banner to admin home feeds
parent
83eadbb811
commit
b0fb198829
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Services\Internal\SoftwareUpdateService;
|
||||||
|
|
||||||
|
class SoftwareUpdateController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->middleware('auth');
|
||||||
|
$this->middleware('admin');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSoftwareUpdateCheck(Request $request)
|
||||||
|
{
|
||||||
|
$res = SoftwareUpdateService::get();
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Internal;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Http\Client\ConnectionException;
|
||||||
|
use Illuminate\Http\Client\RequestException;
|
||||||
|
|
||||||
|
class SoftwareUpdateService
|
||||||
|
{
|
||||||
|
const CACHE_KEY = 'pf:services:software-update:';
|
||||||
|
|
||||||
|
public static function get()
|
||||||
|
{
|
||||||
|
$curVersion = config('pixelfed.version');
|
||||||
|
|
||||||
|
$versions = Cache::remember(self::CACHE_KEY . 'latest:v1.0.0', 1800, function() {
|
||||||
|
return self::fetchLatest();
|
||||||
|
});
|
||||||
|
|
||||||
|
if(!$versions || !isset($versions['latest'], $versions['latest']['version'])) {
|
||||||
|
$hideWarning = (bool) config('instance.software-update.disable_failed_warning');
|
||||||
|
return [
|
||||||
|
'current' => $curVersion,
|
||||||
|
'latest' => [
|
||||||
|
'version' => null,
|
||||||
|
'published_at' => null,
|
||||||
|
'url' => null,
|
||||||
|
],
|
||||||
|
'running_latest' => $hideWarning ? true : null
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'current' => $curVersion,
|
||||||
|
'latest' => [
|
||||||
|
'version' => $versions['latest']['version'],
|
||||||
|
'published_at' => $versions['latest']['published_at'],
|
||||||
|
'url' => $versions['latest']['url'],
|
||||||
|
],
|
||||||
|
'running_latest' => strval($versions['latest']['version']) === strval($curVersion)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function fetchLatest()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$res = Http::withOptions(['allow_redirects' => false])
|
||||||
|
->timeout(5)
|
||||||
|
->connectTimeout(5)
|
||||||
|
->retry(2, 500)
|
||||||
|
->get('https://versions.pixelfed.org/versions.json');
|
||||||
|
} catch (RequestException $e) {
|
||||||
|
return;
|
||||||
|
} catch (ConnectionException $e) {
|
||||||
|
return;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$res->ok()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res->json();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue