mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Merge pull request #4934 from pixelfed/staging
Add Software Update banner to admin home feeds
This commit is contained in:
commit
25dd2e46fe
11 changed files with 170 additions and 3 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
- Autospam Live Filters - block remote activities based on comma separated keywords ([40b45b2a](https://github.com/pixelfed/pixelfed/commit/40b45b2a))
|
- Autospam Live Filters - block remote activities based on comma separated keywords ([40b45b2a](https://github.com/pixelfed/pixelfed/commit/40b45b2a))
|
||||||
|
- Added Software Update banner to admin home feeds ([b0fb1988](https://github.com/pixelfed/pixelfed/commit/b0fb1988))
|
||||||
|
|
||||||
### Updated
|
### Updated
|
||||||
|
|
||||||
|
|
21
app/Http/Controllers/SoftwareUpdateController.php
Normal file
21
app/Http/Controllers/SoftwareUpdateController.php
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
68
app/Services/Internal/SoftwareUpdateService.php
Normal file
68
app/Services/Internal/SoftwareUpdateService.php
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -140,5 +140,9 @@ return [
|
||||||
'max_children' => env('INSTANCE_PARENTAL_CONTROLS_MAX_CHILDREN', 1),
|
'max_children' => env('INSTANCE_PARENTAL_CONTROLS_MAX_CHILDREN', 1),
|
||||||
'auto_verify_email' => true,
|
'auto_verify_email' => true,
|
||||||
],
|
],
|
||||||
]
|
],
|
||||||
|
|
||||||
|
'software-update' => [
|
||||||
|
'disable_failed_warning' => env('INSTANCE_SOFTWARE_UPDATE_DISABLE_FAILED_WARNING', false)
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
BIN
public/js/home.chunk.88eeebf6c53d4dca.js
vendored
Normal file
BIN
public/js/home.chunk.88eeebf6c53d4dca.js
vendored
Normal file
Binary file not shown.
BIN
public/js/home.chunk.ada2cbf0ec3271bd.js
vendored
BIN
public/js/home.chunk.ada2cbf0ec3271bd.js
vendored
Binary file not shown.
BIN
public/js/manifest.js
vendored
BIN
public/js/manifest.js
vendored
Binary file not shown.
Binary file not shown.
|
@ -9,6 +9,48 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-8 col-lg-6 px-0">
|
<div class="col-md-8 col-lg-6 px-0">
|
||||||
|
<template v-if="showUpdateWarning && updateInfo && updateInfo.hasOwnProperty('running_latest')">
|
||||||
|
<div class="card rounded-lg mb-4 ft-std" style="background: #e11d48;border: 3px dashed #fff">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between align-items-center flex-column flex-lg-row" style="gap:1rem">
|
||||||
|
<div class="d-flex justify-content-between align-items-center" style="gap:1rem">
|
||||||
|
<i class="d-none d-sm-block far fa-exclamation-triangle fa-5x text-white"></i>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h1 class="h3 font-weight-bold text-light mb-0">New Update Available</h1>
|
||||||
|
<p class="mb-0 text-white" style="font-size:18px;">Update your Pixelfed server as soon as possible!</p>
|
||||||
|
<p class="mb-n1 text-white small" style="opacity:.7">Once you update, this message will disappear.</p>
|
||||||
|
<p class="mb-0 text-white small d-flex" style="opacity:.5;gap:1rem;">
|
||||||
|
<span>Current version: <strong>{{ updateInfo?.current ?? 'Unknown' }}</strong></span>
|
||||||
|
<span>Latest version: <strong>{{ updateInfo?.latest?.version ?? 'Unknown' }}</strong></span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<a v-if="updateInfo.latest.url" class="btn btn-light font-weight-bold" :href="updateInfo.latest.url" target="_blank">View Update</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template v-if="showUpdateConnectionWarning">
|
||||||
|
<div class="card rounded-lg mb-4 ft-std" style="background: #e11d48;border: 3px dashed #fff">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between align-items-center flex-column flex-lg-row" style="gap:1rem">
|
||||||
|
<div class="d-flex justify-content-between align-items-center" style="gap:1rem">
|
||||||
|
<i class="d-none d-sm-block far fa-exclamation-triangle fa-5x text-white"></i>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h1 class="h3 font-weight-bold text-light mb-1">Software Update Check Failed</h1>
|
||||||
|
<p class="mb-1 text-white" style="font-size:18px;line-height: 1.2;">We attempted to check if there is a new version available, however we encountered an error. <a href="https://github.com/pixelfed/pixelfed/releases" class="text-white font-weight-bold" style="text-decoration: underline;" target="_blank">Click here</a> to view the latest releases.</p>
|
||||||
|
<p class="mb-0 text-white small">You can set <code class="text-white">INSTANCE_SOFTWARE_UPDATE_DISABLE_FAILED_WARNING=true</code> to remove this warning.</p>
|
||||||
|
<p class="mb-0 text-white small" style="opacity:.7">Current version: {{ updateInfo?.current ?? 'Unknown' }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
<story-carousel
|
<story-carousel
|
||||||
v-if="storiesEnabled"
|
v-if="storiesEnabled"
|
||||||
:profile="profile" />
|
:profile="profile" />
|
||||||
|
@ -59,7 +101,6 @@
|
||||||
"rightbar": Rightbar,
|
"rightbar": Rightbar,
|
||||||
"story-carousel": StoryCarousel,
|
"story-carousel": StoryCarousel,
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isLoaded: false,
|
isLoaded: false,
|
||||||
|
@ -67,7 +108,10 @@
|
||||||
recommended: [],
|
recommended: [],
|
||||||
trending: [],
|
trending: [],
|
||||||
storiesEnabled: false,
|
storiesEnabled: false,
|
||||||
shouldRefresh: false
|
shouldRefresh: false,
|
||||||
|
showUpdateWarning: false,
|
||||||
|
showUpdateConnectionWarning: false,
|
||||||
|
updateInfo: undefined,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -84,10 +128,33 @@
|
||||||
this.profile = window._sharedData.user;
|
this.profile = window._sharedData.user;
|
||||||
this.isLoaded = true;
|
this.isLoaded = true;
|
||||||
this.storiesEnabled = window.App?.config?.features?.hasOwnProperty('stories') ? window.App.config.features.stories : false;
|
this.storiesEnabled = window.App?.config?.features?.hasOwnProperty('stories') ? window.App.config.features.stories : false;
|
||||||
|
|
||||||
|
if(this.profile.is_admin) {
|
||||||
|
this.softwareUpdateCheck();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
updateProfile(delta) {
|
updateProfile(delta) {
|
||||||
this.profile = Object.assign(this.profile, delta);
|
this.profile = Object.assign(this.profile, delta);
|
||||||
|
},
|
||||||
|
|
||||||
|
softwareUpdateCheck() {
|
||||||
|
axios.get('/api/web-admin/software-update/check')
|
||||||
|
.then(res => {
|
||||||
|
if(!res || !res.data || !res.data.hasOwnProperty('running_latest') || res.data.running_latest) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(res.data.running_latest === null) {
|
||||||
|
this.updateInfo = res.data;
|
||||||
|
this.showUpdateConnectionWarning = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.updateInfo = res.data;
|
||||||
|
this.showUpdateWarning = !res.data.running_latest;
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
this.showUpdateConnectionWarning = true;
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Http\Controllers\SoftwareUpdateController;
|
||||||
|
|
||||||
Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofactor', 'localization'])->group(function () {
|
Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofactor', 'localization'])->group(function () {
|
||||||
Route::group(['prefix' => 'api'], function () {
|
Route::group(['prefix' => 'api'], function () {
|
||||||
Route::get('search', 'SearchController@searchAPI');
|
Route::get('search', 'SearchController@searchAPI');
|
||||||
|
@ -7,6 +9,10 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
|
||||||
Route::get('v1/polls/{id}', 'PollController@getPoll');
|
Route::get('v1/polls/{id}', 'PollController@getPoll');
|
||||||
Route::post('v1/polls/{id}/votes', 'PollController@vote');
|
Route::post('v1/polls/{id}/votes', 'PollController@vote');
|
||||||
|
|
||||||
|
Route::group(['prefix' => 'web-admin'], function() {
|
||||||
|
Route::get('software-update/check', [SoftwareUpdateController::class, 'getSoftwareUpdateCheck']);
|
||||||
|
});
|
||||||
|
|
||||||
Route::group(['prefix' => 'compose'], function() {
|
Route::group(['prefix' => 'compose'], function() {
|
||||||
Route::group(['prefix' => 'v0'], function() {
|
Route::group(['prefix' => 'v0'], function() {
|
||||||
Route::post('/media/upload', 'ComposeController@mediaUpload');
|
Route::post('/media/upload', 'ComposeController@mediaUpload');
|
||||||
|
|
Loading…
Reference in a new issue