From 3c8bcb1a2b4a62ecd95a33a157b74a54c07e433f Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Mon, 13 May 2024 18:43:21 +0300 Subject: [PATCH] update --- web/app/Livewire/FileManager.php | 16 ++++++++++++++-- web/app/Models/FileItem.php | 21 +++++++++++++++------ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/web/app/Livewire/FileManager.php b/web/app/Livewire/FileManager.php index 0089ce1..8490a80 100644 --- a/web/app/Livewire/FileManager.php +++ b/web/app/Livewire/FileManager.php @@ -2,7 +2,9 @@ namespace App\Livewire; +use App\Models\Domain; use App\Models\FileItem; +use App\Models\HostingSubscription; use Filament\Forms\Components\FileUpload; use Filament\Forms\Components\TextInput; use Filament\Pages\Page; @@ -37,6 +39,16 @@ class FileManager extends Page implements HasTable public function table(Table $table): Table { + $hostingSubscription = HostingSubscription::where('id', 16)->first(); + $findDomain = Domain::where('hosting_subscription_id', $hostingSubscription->id)->where('is_main',1)->first(); + $this->disk = $findDomain->home_root; + + $storage = Storage::build([ + 'driver' => 'local', + 'throw' => false, + 'root' => $this->disk, + ]); + return $table ->heading($this->path ?: 'Root') ->query( @@ -70,13 +82,13 @@ class FileManager extends Page implements HasTable ViewAction::make('open') ->label('Open') ->hidden(fn (FileItem $record): bool => ! $record->canOpen()) - ->url(fn (FileItem $record): string => Storage::disk($this->disk)->url($record->path)) + ->url(fn (FileItem $record): string => $storage->url($record->path)) ->openUrlInNewTab(), Action::make('download') ->label('Download') ->icon('heroicon-o-document-arrow-down') ->hidden(fn (FileItem $record): bool => $record->isFolder()) - ->action(fn (FileItem $record) => Storage::disk($this->disk)->download($record->path)), + ->action(fn (FileItem $record) => $storage->download($record->path)), DeleteAction::make('delete') ->successNotificationTitle('File deleted') ->hidden(fn (FileItem $record): bool => $record->isPreviousPath()) diff --git a/web/app/Models/FileItem.php b/web/app/Models/FileItem.php index 746cb58..7e4dcd9 100644 --- a/web/app/Models/FileItem.php +++ b/web/app/Models/FileItem.php @@ -32,10 +32,19 @@ class FileItem extends Model return static::query(); } + public function storageInstance() + { + return Storage::build([ + 'driver' => 'local', + 'throw' => false, + 'root' => static::$disk, + ]); + } + public function isFolder(): bool { return $this->type === 'Folder' - && is_dir(Storage::disk(static::$disk)->path($this->path)); + && is_dir($this->storageInstance()->path($this->path)); } public function isPreviousPath(): bool @@ -46,17 +55,17 @@ class FileItem extends Model public function delete(): bool { if ($this->isFolder()) { - return Storage::disk(static::$disk)->deleteDirectory($this->path); + return $this->storageInstance()->deleteDirectory($this->path); } - return Storage::disk(static::$disk)->delete($this->path); + return $this->storageInstance()->delete($this->path); } public function canOpen(): bool { return $this->type !== 'Folder' - && Storage::disk(static::$disk)->exists($this->path) - && Storage::disk(static::$disk)->getVisibility($this->path) === FilesystemContract::VISIBILITY_PUBLIC; + && $this->storageInstance()->exists($this->path) + && $this->storageInstance()->getVisibility($this->path) === FilesystemContract::VISIBILITY_PUBLIC; } public function getRows(): array @@ -76,7 +85,7 @@ class FileItem extends Model ]; } - $storage = Storage::disk(static::$disk); + $storage = $this->storageInstance(); return collect($backPath)->push( ...collect($storage->directories(static::$path))