diff --git a/app/Console/Commands/Egg/UpdateEggIndexCommand.php b/app/Console/Commands/Egg/UpdateEggIndexCommand.php new file mode 100644 index 000000000..8ef7646b2 --- /dev/null +++ b/app/Console/Commands/Egg/UpdateEggIndexCommand.php @@ -0,0 +1,46 @@ +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; + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 48fbe6b84..8421c1b82 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -3,6 +3,7 @@ namespace App\Console; use App\Console\Commands\Egg\CheckEggUpdatesCommand; +use App\Console\Commands\Egg\UpdateEggIndexCommand; use App\Console\Commands\Maintenance\CleanServiceBackupFilesCommand; use App\Console\Commands\Maintenance\PruneImagesCommand; use App\Console\Commands\Maintenance\PruneOrphanedBackupsCommand; @@ -41,7 +42,9 @@ class Kernel extends ConsoleKernel $schedule->command(CleanServiceBackupFilesCommand::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')) { // Every 30 minutes, run the backup pruning command so that any abandoned backups can be deleted. diff --git a/app/Filament/Components/Actions/ImportEggAction.php b/app/Filament/Components/Actions/ImportEggAction.php index c6e3b8b58..615cbe0ba 100644 --- a/app/Filament/Components/Actions/ImportEggAction.php +++ b/app/Filament/Components/Actions/ImportEggAction.php @@ -2,6 +2,7 @@ namespace App\Filament\Components\Actions; +use App\Console\Commands\Egg\UpdateEggIndexCommand; use App\Models\Egg; use App\Services\Eggs\Sharing\EggImporterService; use Closure; @@ -9,11 +10,16 @@ use Exception; use Filament\Actions\Action; use Filament\Forms\Components\FileUpload; use Filament\Forms\Components\Repeater; +use Filament\Forms\Components\Select; use Filament\Forms\Components\Tabs; use Filament\Forms\Components\Tabs\Tab; use Filament\Forms\Components\TextInput; +use Filament\Forms\Get; +use Filament\Forms\Set; use Filament\Notifications\Notification; use Illuminate\Support\Arr; +use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Str; use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; class ImportEggAction extends Action @@ -97,7 +103,28 @@ class ImportEggAction extends Action Tab::make(trans('admin/egg.import.url')) ->icon('tabler-world-upload') ->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') + ->label('') ->itemLabel(fn (array $state) => str($state['url'])->afterLast('/egg-')->before('.json')->headline()) ->hint(trans('admin/egg.import.url_help')) ->addActionLabel(trans('admin/egg.import.add_url')) diff --git a/app/Filament/Components/Tables/Actions/ImportEggAction.php b/app/Filament/Components/Tables/Actions/ImportEggAction.php index 426ba46b9..b51576535 100644 --- a/app/Filament/Components/Tables/Actions/ImportEggAction.php +++ b/app/Filament/Components/Tables/Actions/ImportEggAction.php @@ -8,12 +8,16 @@ use Closure; use Exception; use Filament\Forms\Components\FileUpload; use Filament\Forms\Components\Repeater; +use Filament\Forms\Components\Select; use Filament\Forms\Components\Tabs; use Filament\Forms\Components\Tabs\Tab; use Filament\Forms\Components\TextInput; +use Filament\Forms\Get; +use Filament\Forms\Set; use Filament\Notifications\Notification; use Filament\Tables\Actions\Action; use Illuminate\Support\Arr; +use Illuminate\Support\Str; use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; class ImportEggAction extends Action @@ -97,6 +101,21 @@ class ImportEggAction extends Action Tab::make(trans('admin/egg.import.url')) ->icon('tabler-world-upload') ->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') ->itemLabel(fn (array $state) => str($state['url'])->afterLast('/egg-')->before('.json')->headline()) ->hint(trans('admin/egg.import.url_help')) diff --git a/lang/en/admin/egg.php b/lang/en/admin/egg.php index db7171f2b..365fa1670 100644 --- a/lang/en/admin/egg.php +++ b/lang/en/admin/egg.php @@ -18,6 +18,8 @@ return [ 'add_url' => 'New URL', 'import_failed' => 'Import Failed', 'import_success' => 'Import Success', + 'github' => 'Add from Github', + 'refresh' => 'Refresh', ], 'in_use' => 'In Use', 'servers' => 'Servers',