mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-24 16:34:45 +02:00
Fix DaemonFileRepository
in ListFiles
(#1109)
* Fix `DaemonFileRepository` in `ListFiles` * Use match for `getPermissionsFromModeBit`
This commit is contained in:
parent
22d02c0df5
commit
5bf23b972d
@ -50,14 +50,10 @@ class ListFiles extends ListRecords
|
|||||||
|
|
||||||
private DaemonFileRepository $fileRepository;
|
private DaemonFileRepository $fileRepository;
|
||||||
|
|
||||||
public function mount(?DaemonFileRepository $fileRepository = null, ?string $path = null): void
|
public function mount(?string $path = null): void
|
||||||
{
|
{
|
||||||
parent::mount();
|
parent::mount();
|
||||||
$this->path = $path ?? '/';
|
$this->path = $path ?? '/';
|
||||||
|
|
||||||
/** @var Server $server */
|
|
||||||
$server = Filament::getTenant();
|
|
||||||
$this->fileRepository = $fileRepository->setServer($server);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBreadcrumbs(): array
|
public function getBreadcrumbs(): array
|
||||||
@ -140,7 +136,7 @@ class ListFiles extends ListRecords
|
|||||||
->action(function ($data, File $file) {
|
->action(function ($data, File $file) {
|
||||||
$files = [['to' => $data['name'], 'from' => $file->name]];
|
$files = [['to' => $data['name'], 'from' => $file->name]];
|
||||||
|
|
||||||
$this->fileRepository
|
$this->getDaemonFileRepository()
|
||||||
->renameFiles($this->path, $files);
|
->renameFiles($this->path, $files);
|
||||||
|
|
||||||
Activity::event('server:file.rename')
|
Activity::event('server:file.rename')
|
||||||
@ -162,7 +158,7 @@ class ListFiles extends ListRecords
|
|||||||
->icon('tabler-copy')
|
->icon('tabler-copy')
|
||||||
->visible(fn (File $file) => $file->is_file)
|
->visible(fn (File $file) => $file->is_file)
|
||||||
->action(function (File $file) {
|
->action(function (File $file) {
|
||||||
$this->fileRepository
|
$this->getDaemonFileRepository()
|
||||||
->copyFile(join_paths($this->path, $file->name));
|
->copyFile(join_paths($this->path, $file->name));
|
||||||
|
|
||||||
Activity::event('server:file.copy')
|
Activity::event('server:file.copy')
|
||||||
@ -201,7 +197,7 @@ class ListFiles extends ListRecords
|
|||||||
|
|
||||||
$files = [['to' => $location, 'from' => $file->name]];
|
$files = [['to' => $location, 'from' => $file->name]];
|
||||||
|
|
||||||
$this->fileRepository
|
$this->getDaemonFileRepository()
|
||||||
->renameFiles($this->path, $files);
|
->renameFiles($this->path, $files);
|
||||||
|
|
||||||
Activity::event('server:file.rename')
|
Activity::event('server:file.rename')
|
||||||
@ -265,7 +261,7 @@ class ListFiles extends ListRecords
|
|||||||
|
|
||||||
$mode = $owner . $group . $public;
|
$mode = $owner . $group . $public;
|
||||||
|
|
||||||
$this->fileRepository
|
$this->getDaemonFileRepository()
|
||||||
->chmodFiles($this->path, [['file' => $file->name, 'mode' => $mode]]);
|
->chmodFiles($this->path, [['file' => $file->name, 'mode' => $mode]]);
|
||||||
|
|
||||||
Notification::make()
|
Notification::make()
|
||||||
@ -278,7 +274,7 @@ class ListFiles extends ListRecords
|
|||||||
->label('Archive')
|
->label('Archive')
|
||||||
->icon('tabler-archive')
|
->icon('tabler-archive')
|
||||||
->action(function (File $file) {
|
->action(function (File $file) {
|
||||||
$this->fileRepository
|
$this->getDaemonFileRepository()
|
||||||
->compressFiles($this->path, [$file->name]);
|
->compressFiles($this->path, [$file->name]);
|
||||||
|
|
||||||
Activity::event('server:file.compress')
|
Activity::event('server:file.compress')
|
||||||
@ -299,7 +295,7 @@ class ListFiles extends ListRecords
|
|||||||
->icon('tabler-archive')
|
->icon('tabler-archive')
|
||||||
->visible(fn (File $file) => $file->isArchive())
|
->visible(fn (File $file) => $file->isArchive())
|
||||||
->action(function (File $file) {
|
->action(function (File $file) {
|
||||||
$this->fileRepository
|
$this->getDaemonFileRepository()
|
||||||
->decompressFile($this->path, $file->name);
|
->decompressFile($this->path, $file->name);
|
||||||
|
|
||||||
Activity::event('server:file.decompress')
|
Activity::event('server:file.decompress')
|
||||||
@ -323,7 +319,7 @@ class ListFiles extends ListRecords
|
|||||||
->modalDescription(fn (File $file) => $file->name)
|
->modalDescription(fn (File $file) => $file->name)
|
||||||
->modalHeading('Delete file?')
|
->modalHeading('Delete file?')
|
||||||
->action(function (File $file) {
|
->action(function (File $file) {
|
||||||
$this->fileRepository
|
$this->getDaemonFileRepository()
|
||||||
->deleteFiles($this->path, [$file->name]);
|
->deleteFiles($this->path, [$file->name]);
|
||||||
|
|
||||||
Activity::event('server:file.delete')
|
Activity::event('server:file.delete')
|
||||||
@ -351,7 +347,7 @@ class ListFiles extends ListRecords
|
|||||||
$location = resolve_path(join_paths($this->path, $data['location']));
|
$location = resolve_path(join_paths($this->path, $data['location']));
|
||||||
|
|
||||||
$files = $files->map(fn ($file) => ['to' => $location, 'from' => $file['name']])->toArray();
|
$files = $files->map(fn ($file) => ['to' => $location, 'from' => $file['name']])->toArray();
|
||||||
$this->fileRepository
|
$this->getDaemonFileRepository()
|
||||||
->renameFiles($this->path, $files);
|
->renameFiles($this->path, $files);
|
||||||
|
|
||||||
Activity::event('server:file.rename')
|
Activity::event('server:file.rename')
|
||||||
@ -369,7 +365,7 @@ class ListFiles extends ListRecords
|
|||||||
->action(function (Collection $files) {
|
->action(function (Collection $files) {
|
||||||
$files = $files->map(fn ($file) => $file['name'])->toArray();
|
$files = $files->map(fn ($file) => $file['name'])->toArray();
|
||||||
|
|
||||||
$this->fileRepository
|
$this->getDaemonFileRepository()
|
||||||
->compressFiles($this->path, $files);
|
->compressFiles($this->path, $files);
|
||||||
|
|
||||||
Activity::event('server:file.compress')
|
Activity::event('server:file.compress')
|
||||||
@ -388,7 +384,7 @@ class ListFiles extends ListRecords
|
|||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_DELETE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_DELETE, $server))
|
||||||
->action(function (Collection $files) {
|
->action(function (Collection $files) {
|
||||||
$files = $files->map(fn ($file) => $file['name'])->toArray();
|
$files = $files->map(fn ($file) => $file['name'])->toArray();
|
||||||
$this->fileRepository
|
$this->getDaemonFileRepository()
|
||||||
->deleteFiles($this->path, $files);
|
->deleteFiles($this->path, $files);
|
||||||
|
|
||||||
Activity::event('server:file.delete')
|
Activity::event('server:file.delete')
|
||||||
@ -418,7 +414,7 @@ class ListFiles extends ListRecords
|
|||||||
->keyBindings('')
|
->keyBindings('')
|
||||||
->modalSubmitActionLabel('Create')
|
->modalSubmitActionLabel('Create')
|
||||||
->action(function ($data) {
|
->action(function ($data) {
|
||||||
$this->fileRepository
|
$this->getDaemonFileRepository()
|
||||||
->putContent(join_paths($this->path, $data['name']), $data['editor'] ?? '');
|
->putContent(join_paths($this->path, $data['name']), $data['editor'] ?? '');
|
||||||
|
|
||||||
Activity::event('server:file.write')
|
Activity::event('server:file.write')
|
||||||
@ -446,7 +442,7 @@ class ListFiles extends ListRecords
|
|||||||
->label('New Folder')
|
->label('New Folder')
|
||||||
->color('gray')
|
->color('gray')
|
||||||
->action(function ($data) {
|
->action(function ($data) {
|
||||||
$this->fileRepository
|
$this->getDaemonFileRepository()
|
||||||
->createDirectory($data['name'], $this->path);
|
->createDirectory($data['name'], $this->path);
|
||||||
|
|
||||||
Activity::event('server:file.create-directory')
|
Activity::event('server:file.create-directory')
|
||||||
@ -465,7 +461,7 @@ class ListFiles extends ListRecords
|
|||||||
if (count($data['files']) > 0 && !isset($data['url'])) {
|
if (count($data['files']) > 0 && !isset($data['url'])) {
|
||||||
/** @var UploadedFile $file */
|
/** @var UploadedFile $file */
|
||||||
foreach ($data['files'] as $file) {
|
foreach ($data['files'] as $file) {
|
||||||
$this->fileRepository
|
$this->getDaemonFileRepository()
|
||||||
->putContent(join_paths($this->path, $file->getClientOriginalName()), $file->getContent());
|
->putContent(join_paths($this->path, $file->getClientOriginalName()), $file->getContent());
|
||||||
|
|
||||||
Activity::event('server:file.uploaded')
|
Activity::event('server:file.uploaded')
|
||||||
@ -474,7 +470,7 @@ class ListFiles extends ListRecords
|
|||||||
->log();
|
->log();
|
||||||
}
|
}
|
||||||
} elseif ($data['url'] !== null) {
|
} elseif ($data['url'] !== null) {
|
||||||
$this->fileRepository
|
$this->getDaemonFileRepository()
|
||||||
->pull($data['url'], $this->path);
|
->pull($data['url'], $this->path);
|
||||||
|
|
||||||
Activity::event('server:file.pull')
|
Activity::event('server:file.pull')
|
||||||
@ -542,22 +538,24 @@ class ListFiles extends ListRecords
|
|||||||
*/
|
*/
|
||||||
private function getPermissionsFromModeBit(int $mode): array
|
private function getPermissionsFromModeBit(int $mode): array
|
||||||
{
|
{
|
||||||
if ($mode === 1) {
|
return match ($mode) {
|
||||||
return ['execute'];
|
1 => ['execute'],
|
||||||
} elseif ($mode === 2) {
|
2 => ['write'],
|
||||||
return ['write'];
|
3 => ['write', 'execute'],
|
||||||
} elseif ($mode === 3) {
|
4 => ['read'],
|
||||||
return ['write', 'execute'];
|
5 => ['read', 'execute'],
|
||||||
} elseif ($mode === 4) {
|
6 => ['read', 'write'],
|
||||||
return ['read'];
|
7 => ['read', 'write', 'execute'],
|
||||||
} elseif ($mode === 5) {
|
default => [],
|
||||||
return ['read', 'execute'];
|
};
|
||||||
} elseif ($mode === 6) {
|
|
||||||
return ['read', 'write'];
|
|
||||||
} elseif ($mode === 7) {
|
|
||||||
return ['read', 'write', 'execute'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
private function getDaemonFileRepository(): DaemonFileRepository
|
||||||
|
{
|
||||||
|
/** @var Server $server */
|
||||||
|
$server = Filament::getTenant();
|
||||||
|
$this->fileRepository ??= (new DaemonFileRepository())->setServer($server);
|
||||||
|
|
||||||
|
return $this->fileRepository;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user