From 13b5e89f81c8f57c0b1c8966fb791ee79a787de3 Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Thu, 2 May 2024 18:38:42 +0300 Subject: [PATCH] update --- web/app/BackupStorage.php | 12 +++++++++--- web/app/Filament/Resources/BackupResource.php | 9 ++++++--- .../Http/Controllers/BackupDownloadController.php | 5 ++++- web/app/Models/Backup.php | 10 ++++++---- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/web/app/BackupStorage.php b/web/app/BackupStorage.php index 87cedcf..468177a 100644 --- a/web/app/BackupStorage.php +++ b/web/app/BackupStorage.php @@ -50,20 +50,26 @@ class BackupStorage return $rootPath; } - public static function getInstance() + public static function getInstance($path = false) { $rootPath = self::getPath(); + if ($path) { + $rootPath = $path; + } $storageBuild = Storage::build([ 'driver' => 'local', 'throw' => false, 'root' => $rootPath, ]); - $storageBuild->buildTemporaryUrlsUsing(function ($path, $expiration, $options) { + $storageBuild->buildTemporaryUrlsUsing(function ($path, $expiration, $options) use($rootPath) { return URL::temporarySignedRoute( 'backup.download', $expiration, - array_merge($options, ['path' => $path]) + array_merge($options, [ + 'path' => $path, + 'root_path' => $rootPath, + ]) ); }); diff --git a/web/app/Filament/Resources/BackupResource.php b/web/app/Filament/Resources/BackupResource.php index c854d1f..268e21b 100644 --- a/web/app/Filament/Resources/BackupResource.php +++ b/web/app/Filament/Resources/BackupResource.php @@ -2,6 +2,7 @@ namespace App\Filament\Resources; +use App\BackupStorage; use App\Filament\Enums\BackupStatus; use App\Filament\Enums\BackupType; use App\Filament\Resources\BackupResource\Pages; @@ -102,9 +103,11 @@ class BackupResource extends Resource 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); + + $backupStorage = BackupStorage::getInstance($backup->root_path); + $tempUrl = $backupStorage->temporaryUrl($backup->file_name, Carbon::now()->addMinutes(5)); + + return redirect($tempUrl); }), Tables\Actions\ViewAction::make(), ]) diff --git a/web/app/Http/Controllers/BackupDownloadController.php b/web/app/Http/Controllers/BackupDownloadController.php index e5c7c93..0f1b87e 100644 --- a/web/app/Http/Controllers/BackupDownloadController.php +++ b/web/app/Http/Controllers/BackupDownloadController.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace App\Http\Controllers; +use App\BackupStorage; use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\URL; @@ -19,7 +20,9 @@ class BackupDownloadController extends Controller return response('Invalid URL provided'); } - return Storage::disk('backups')->download($request->get('path')); + $backupStorage = BackupStorage::getInstance($request->get('root_path')); + return $backupStorage->download($request->get('path')); + } } diff --git a/web/app/Models/Backup.php b/web/app/Models/Backup.php index 86d8863..18729ce 100644 --- a/web/app/Models/Backup.php +++ b/web/app/Models/Backup.php @@ -89,7 +89,6 @@ class Backup extends Model public function checkBackup() { if ($this->status == BackupStatus::Processing) { - $backupDoneFile = $this->path.'/backup.done'; if (file_exists($backupDoneFile)) { @@ -98,7 +97,7 @@ class Backup extends Model mkdir($tempValidatePath); } - shell_exec('cd '.$tempValidatePath.' && unzip -o '.Storage::disk('backups')->path($this->filepath)); + shell_exec('cd '.$tempValidatePath.' && unzip -o '.$this->file_path); $validateDatabaseFile = $tempValidatePath.'/database.sql'; $validateEnvFile = $tempValidatePath.'/.env'; @@ -136,10 +135,13 @@ class Backup extends Model } ShellApi::safeDelete($this->path,[ - Storage::path('backups') + $this->root_path + ]); + ShellApi::safeDelete($this->temp_path,[ + $this->root_path ]); - $this->size = filesize(Storage::disk('backups')->path($this->filepath)); + $this->size = filesize($this->file_path); $this->status = 'completed'; $this->completed = true; $this->completed_at = now();