Add "egg index" and dropdown to egg importer (#1451)

Co-authored-by: notCharles <charles@pelican.dev>
This commit is contained in:
Boy132 2025-06-26 01:50:09 +02:00 committed by GitHub
parent dca37ccc95
commit 68f72b9b4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 98 additions and 1 deletions

View File

@ -0,0 +1,46 @@
<?php
namespace App\Console\Commands\Egg;
use Exception;
use Illuminate\Console\Command;
class UpdateEggIndexCommand extends Command
{
protected $signature = 'p:egg:update-index';
public function handle(): int
{
try {
$data = file_get_contents('https://raw.githubusercontent.com/pelican-eggs/pelican-eggs.github.io/refs/heads/main/content/pelican.json');
$data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
} catch (Exception $exception) {
$this->error($exception->getMessage());
return 1;
}
$index = [];
foreach ($data['nests'] as $nest) {
$nestName = $nest['nest_type'];
$this->info("Nest: $nestName");
$nestEggs = [];
foreach ($nest['Eggs'] as $egg) {
$eggName = $egg['egg']['name'];
$this->comment("Egg: $eggName");
$nestEggs[$egg['download_url']] = $eggName;
}
$index[$nestName] = $nestEggs;
$this->info('');
}
cache()->forever('eggs.index', $index);
return 0;
}
}

View File

@ -3,6 +3,7 @@
namespace App\Console; namespace App\Console;
use App\Console\Commands\Egg\CheckEggUpdatesCommand; use App\Console\Commands\Egg\CheckEggUpdatesCommand;
use App\Console\Commands\Egg\UpdateEggIndexCommand;
use App\Console\Commands\Maintenance\CleanServiceBackupFilesCommand; use App\Console\Commands\Maintenance\CleanServiceBackupFilesCommand;
use App\Console\Commands\Maintenance\PruneImagesCommand; use App\Console\Commands\Maintenance\PruneImagesCommand;
use App\Console\Commands\Maintenance\PruneOrphanedBackupsCommand; use App\Console\Commands\Maintenance\PruneOrphanedBackupsCommand;
@ -41,7 +42,9 @@ class Kernel extends ConsoleKernel
$schedule->command(CleanServiceBackupFilesCommand::class)->daily(); $schedule->command(CleanServiceBackupFilesCommand::class)->daily();
$schedule->command(PruneImagesCommand::class)->daily(); $schedule->command(PruneImagesCommand::class)->daily();
$schedule->command(CheckEggUpdatesCommand::class)->hourly();
$schedule->command(CheckEggUpdatesCommand::class)->daily();
$schedule->command(UpdateEggIndexCommand::class)->daily();
if (config('backups.prune_age')) { if (config('backups.prune_age')) {
// Every 30 minutes, run the backup pruning command so that any abandoned backups can be deleted. // Every 30 minutes, run the backup pruning command so that any abandoned backups can be deleted.

View File

@ -2,6 +2,7 @@
namespace App\Filament\Components\Actions; namespace App\Filament\Components\Actions;
use App\Console\Commands\Egg\UpdateEggIndexCommand;
use App\Models\Egg; use App\Models\Egg;
use App\Services\Eggs\Sharing\EggImporterService; use App\Services\Eggs\Sharing\EggImporterService;
use Closure; use Closure;
@ -9,11 +10,16 @@ use Exception;
use Filament\Actions\Action; use Filament\Actions\Action;
use Filament\Forms\Components\FileUpload; use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Repeater; use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Tabs; use Filament\Forms\Components\Tabs;
use Filament\Forms\Components\Tabs\Tab; use Filament\Forms\Components\Tabs\Tab;
use Filament\Forms\Components\TextInput; use Filament\Forms\Components\TextInput;
use Filament\Forms\Get;
use Filament\Forms\Set;
use Filament\Notifications\Notification; use Filament\Notifications\Notification;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Str;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
class ImportEggAction extends Action class ImportEggAction extends Action
@ -97,7 +103,28 @@ class ImportEggAction extends Action
Tab::make(trans('admin/egg.import.url')) Tab::make(trans('admin/egg.import.url'))
->icon('tabler-world-upload') ->icon('tabler-world-upload')
->schema([ ->schema([
Select::make('github')
->label(trans('admin/egg.import.github'))
->options(cache('eggs.index'))
->selectablePlaceholder(false)
->searchable()
->preload()
->live()
->hintIcon('tabler-refresh')
->hintIconTooltip(trans('admin/egg.import.refresh'))
->hintAction(function () {
Artisan::call(UpdateEggIndexCommand::class);
})
->afterStateUpdated(function ($state, Set $set, Get $get) use ($isMultiple) {
if ($state) {
$urls = $isMultiple ? $get('urls') : [];
$urls[Str::uuid()->toString()] = ['url' => $state];
$set('urls', $urls);
$set('github', null);
}
}),
Repeater::make('urls') Repeater::make('urls')
->label('')
->itemLabel(fn (array $state) => str($state['url'])->afterLast('/egg-')->before('.json')->headline()) ->itemLabel(fn (array $state) => str($state['url'])->afterLast('/egg-')->before('.json')->headline())
->hint(trans('admin/egg.import.url_help')) ->hint(trans('admin/egg.import.url_help'))
->addActionLabel(trans('admin/egg.import.add_url')) ->addActionLabel(trans('admin/egg.import.add_url'))

View File

@ -8,12 +8,16 @@ use Closure;
use Exception; use Exception;
use Filament\Forms\Components\FileUpload; use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Repeater; use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Tabs; use Filament\Forms\Components\Tabs;
use Filament\Forms\Components\Tabs\Tab; use Filament\Forms\Components\Tabs\Tab;
use Filament\Forms\Components\TextInput; use Filament\Forms\Components\TextInput;
use Filament\Forms\Get;
use Filament\Forms\Set;
use Filament\Notifications\Notification; use Filament\Notifications\Notification;
use Filament\Tables\Actions\Action; use Filament\Tables\Actions\Action;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
class ImportEggAction extends Action class ImportEggAction extends Action
@ -97,6 +101,21 @@ class ImportEggAction extends Action
Tab::make(trans('admin/egg.import.url')) Tab::make(trans('admin/egg.import.url'))
->icon('tabler-world-upload') ->icon('tabler-world-upload')
->schema([ ->schema([
Select::make('github')
->label(trans('admin/egg.import.github'))
->options(cache('eggs.index'))
->selectablePlaceholder(false)
->searchable()
->preload()
->live()
->afterStateUpdated(function ($state, Set $set, Get $get) use ($isMultiple) {
if ($state) {
$urls = $isMultiple ? $get('urls') : [];
$urls[Str::uuid()->toString()] = ['url' => $state];
$set('urls', $urls);
$set('github', null);
}
}),
Repeater::make('urls') Repeater::make('urls')
->itemLabel(fn (array $state) => str($state['url'])->afterLast('/egg-')->before('.json')->headline()) ->itemLabel(fn (array $state) => str($state['url'])->afterLast('/egg-')->before('.json')->headline())
->hint(trans('admin/egg.import.url_help')) ->hint(trans('admin/egg.import.url_help'))

View File

@ -18,6 +18,8 @@ return [
'add_url' => 'New URL', 'add_url' => 'New URL',
'import_failed' => 'Import Failed', 'import_failed' => 'Import Failed',
'import_success' => 'Import Success', 'import_success' => 'Import Success',
'github' => 'Add from Github',
'refresh' => 'Refresh',
], ],
'in_use' => 'In Use', 'in_use' => 'In Use',
'servers' => 'Servers', 'servers' => 'Servers',