Add changelog preview when a new update is available (#1792)

Co-authored-by: Boy132 <mail@boy132.de>
This commit is contained in:
Letter N 2025-10-12 09:34:38 +08:00 committed by GitHub
parent 266e3779d5
commit e589f972fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 0 deletions

View File

@ -43,7 +43,18 @@ class UpdateWidget extends FormWidget
->iconColor('warning') ->iconColor('warning')
->schema([ ->schema([
TextEntry::make('info') TextEntry::make('info')
->hiddenLabel()
->state(trans('admin/dashboard.sections.intro-update-available.content', ['latestVersion' => $this->softwareVersionService->latestPanelVersion()])), ->state(trans('admin/dashboard.sections.intro-update-available.content', ['latestVersion' => $this->softwareVersionService->latestPanelVersion()])),
Section::make(trans('admin/dashboard.sections.intro-update-available.button_changelog'))
->icon('tabler-script')
->collapsible()
->collapsed()
->schema([
TextEntry::make('changelog')
->hiddenLabel()
->state($this->softwareVersionService->latestPanelVersionChangelog())
->markdown(),
]),
]) ])
->headerActions([ ->headerActions([
Action::make('update') Action::make('update')

View File

@ -7,6 +7,24 @@ use Illuminate\Support\Facades\Http;
class SoftwareVersionService class SoftwareVersionService
{ {
public function latestPanelVersionChangelog(): string
{
$key = 'panel:latest_version_changelog';
if (cache()->get($key) === 'error') {
cache()->forget($key);
}
return cache()->remember($key, now()->addMinutes(config('panel.cdn.cache_time', 60)), function () {
try {
$response = Http::timeout(5)->connectTimeout(1)->get('https://api.github.com/repos/pelican-dev/panel/releases/latest')->throw()->json();
return $response['body'];
} catch (Exception) {
return 'error';
}
});
}
public function latestPanelVersion(): string public function latestPanelVersion(): string
{ {
$key = 'panel:latest_version'; $key = 'panel:latest_version';

View File

@ -17,6 +17,7 @@ return [
'intro-update-available' => [ 'intro-update-available' => [
'heading' => 'Update available', 'heading' => 'Update available',
'content' => ':latestVersion is now available! Read our documentation to update your Panel.', 'content' => ':latestVersion is now available! Read our documentation to update your Panel.',
'button_changelog' => 'What\'s New?',
], ],
'intro-no-update' => [ 'intro-no-update' => [
'heading' => 'Your Panel is up to date', 'heading' => 'Your Panel is up to date',