mirror of
https://github.com/PhyreApps/PhyrePanel.git
synced 2024-11-21 23:20:24 +00:00
update
This commit is contained in:
parent
2d217d93fb
commit
3c8bcb1a2b
2 changed files with 29 additions and 8 deletions
|
@ -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())
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue