diff --git a/web/app/Filament/Resources/BackupResource.php b/web/app/Filament/Resources/BackupResource.php index 92170da..ea26207 100644 --- a/web/app/Filament/Resources/BackupResource.php +++ b/web/app/Filament/Resources/BackupResource.php @@ -14,6 +14,8 @@ use Filament\Forms\Get; use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Table; +use Illuminate\Support\Carbon; +use Illuminate\Support\Facades\Storage; use Illuminate\Support\Number; use JaOcero\RadioDeck\Forms\Components\RadioDeck; @@ -89,6 +91,13 @@ class BackupResource extends Resource // ]) ->actions([ + Tables\Actions\Action::make('download') + ->icon('heroicon-o-arrow-down-tray') + ->action(function (Backup $backup) { + $url = Storage::disk('backups') + ->temporaryUrl($backup->filepath, Carbon::now()->addMinutes(5)); + return redirect($url); + }), Tables\Actions\ViewAction::make(), ]) ->defaultSort('id', 'desc') diff --git a/web/app/Http/Controllers/BackupDownloadController.php b/web/app/Http/Controllers/BackupDownloadController.php new file mode 100644 index 0000000..e5c7c93 --- /dev/null +++ b/web/app/Http/Controllers/BackupDownloadController.php @@ -0,0 +1,25 @@ +download($request->get('path')); + } +} + diff --git a/web/app/Providers/AppServiceProvider.php b/web/app/Providers/AppServiceProvider.php index 687739e..1cfec17 100644 --- a/web/app/Providers/AppServiceProvider.php +++ b/web/app/Providers/AppServiceProvider.php @@ -17,6 +17,8 @@ use Filament\Facades\Filament; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Gate; +use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Facades\URL; use Illuminate\Support\ServiceProvider; use Livewire\Livewire; @@ -27,6 +29,15 @@ class AppServiceProvider extends ServiceProvider */ public function register(): void { + // This allows us to generate a temporary url for backups downloading + Storage::disk('backups')->buildTemporaryUrlsUsing(function ($path, $expiration, $options) { + return URL::temporarySignedRoute( + 'backup.download', + $expiration, + array_merge($options, ['path' => $path]) + ); + }); + // Register Phyre Icons set $this->callAfterResolving(Factory::class, function (Factory $factory) { $factory->add('phyre', [ diff --git a/web/config/filesystems.php b/web/config/filesystems.php index e9d9dbd..ba8d3d1 100644 --- a/web/config/filesystems.php +++ b/web/config/filesystems.php @@ -44,6 +44,12 @@ return [ 'throw' => false, ], + 'backups' => [ + 'driver' => 'local', + 'root' => storage_path('app/backups'), + 'throw' => false, + ], + 's3' => [ 'driver' => 's3', 'key' => env('AWS_ACCESS_KEY_ID'), diff --git a/web/routes/web.php b/web/routes/web.php index 90ea70a..81ac968 100644 --- a/web/routes/web.php +++ b/web/routes/web.php @@ -28,3 +28,6 @@ if (!file_exists(storage_path('installed'))) { } Route::get('/installer', \App\Livewire\Installer::class); + +Route::get('backup/download', [\App\Http\Controllers\BackupDownloadController::class, 'download']) + ->name('backup.download');