mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 08:44:46 +02:00
Update File Manager (#814)
* Make Everything Sortable * Replace app calls
This commit is contained in:
parent
0051d9fefc
commit
53460b8d1b
@ -80,12 +80,15 @@ class ListFiles extends ListRecords
|
|||||||
return $table
|
return $table
|
||||||
->paginated([15, 25, 50, 100])
|
->paginated([15, 25, 50, 100])
|
||||||
->defaultPaginationPageOption(15)
|
->defaultPaginationPageOption(15)
|
||||||
->query(fn () => File::get($server, $this->path)->orderByDesc('is_directory')->orderBy('name'))
|
->query(fn () => File::get($server, $this->path)->orderByDesc('is_directory'))
|
||||||
|
->defaultSort('name')
|
||||||
->columns([
|
->columns([
|
||||||
TextColumn::make('name')
|
TextColumn::make('name')
|
||||||
->searchable()
|
->searchable()
|
||||||
|
->sortable()
|
||||||
->icon(fn (File $file) => $file->getIcon()),
|
->icon(fn (File $file) => $file->getIcon()),
|
||||||
BytesColumn::make('size'),
|
BytesColumn::make('size')
|
||||||
|
->sortable(),
|
||||||
DateTimeColumn::make('modified_at')
|
DateTimeColumn::make('modified_at')
|
||||||
->since()
|
->since()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
@ -126,9 +129,8 @@ class ListFiles extends ListRecords
|
|||||||
->default(fn (File $file) => $file->name)
|
->default(fn (File $file) => $file->name)
|
||||||
->required(),
|
->required(),
|
||||||
])
|
])
|
||||||
->action(function ($data, File $file) use ($server) {
|
->action(function ($data, File $file, DaemonFileRepository $fileRepository) use ($server) {
|
||||||
// @phpstan-ignore-next-line
|
$fileRepository
|
||||||
app(DaemonFileRepository::class)
|
|
||||||
->setServer($server)
|
->setServer($server)
|
||||||
->renameFiles($this->path, [['to' => $data['name'], 'from' => $file->name]]);
|
->renameFiles($this->path, [['to' => $data['name'], 'from' => $file->name]]);
|
||||||
|
|
||||||
@ -148,9 +150,8 @@ class ListFiles extends ListRecords
|
|||||||
->label('Copy')
|
->label('Copy')
|
||||||
->icon('tabler-copy')
|
->icon('tabler-copy')
|
||||||
->visible(fn (File $file) => $file->is_file)
|
->visible(fn (File $file) => $file->is_file)
|
||||||
->action(function (File $file) use ($server) {
|
->action(function (File $file, DaemonFileRepository $fileRepository) use ($server) {
|
||||||
// @phpstan-ignore-next-line
|
$fileRepository
|
||||||
app(DaemonFileRepository::class)
|
|
||||||
->setServer($server)
|
->setServer($server)
|
||||||
->copyFile(join_paths($this->path, $file->name));
|
->copyFile(join_paths($this->path, $file->name));
|
||||||
|
|
||||||
@ -170,9 +171,8 @@ class ListFiles extends ListRecords
|
|||||||
->label('Download')
|
->label('Download')
|
||||||
->icon('tabler-download')
|
->icon('tabler-download')
|
||||||
->visible(fn (File $file) => $file->is_file)
|
->visible(fn (File $file) => $file->is_file)
|
||||||
->action(function (File $file) use ($server) {
|
->action(function (File $file, NodeJWTService $service) use ($server) {
|
||||||
// @phpstan-ignore-next-line
|
$token = $service
|
||||||
$token = app(NodeJWTService::class)
|
|
||||||
->setExpiresAt(CarbonImmutable::now()->addMinutes(15))
|
->setExpiresAt(CarbonImmutable::now()->addMinutes(15))
|
||||||
->setUser(auth()->user())
|
->setUser(auth()->user())
|
||||||
->setClaims([
|
->setClaims([
|
||||||
@ -201,11 +201,10 @@ class ListFiles extends ListRecords
|
|||||||
Placeholder::make('new_location')
|
Placeholder::make('new_location')
|
||||||
->content(fn (Get $get) => resolve_path('./' . join_paths($this->path, $get('location')))),
|
->content(fn (Get $get) => resolve_path('./' . join_paths($this->path, $get('location')))),
|
||||||
])
|
])
|
||||||
->action(function ($data, File $file) use ($server) {
|
->action(function ($data, File $file, DaemonFileRepository $fileRepository) use ($server) {
|
||||||
$location = resolve_path(join_paths($this->path, $data['location']));
|
$location = resolve_path(join_paths($this->path, $data['location']));
|
||||||
|
|
||||||
// @phpstan-ignore-next-line
|
$fileRepository
|
||||||
app(DaemonFileRepository::class)
|
|
||||||
->setServer($server)
|
->setServer($server)
|
||||||
->renameFiles($this->path, [['to' => $location, 'from' => $file->name]]);
|
->renameFiles($this->path, [['to' => $location, 'from' => $file->name]]);
|
||||||
|
|
||||||
@ -261,15 +260,14 @@ class ListFiles extends ListRecords
|
|||||||
return $this->getPermissionsFromModeBit($mode);
|
return $this->getPermissionsFromModeBit($mode);
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
->action(function ($data, File $file) use ($server) {
|
->action(function ($data, File $file, DaemonFileRepository $fileRepository) use ($server) {
|
||||||
$owner = (in_array('read', $data['owner']) ? 4 : 0) | (in_array('write', $data['owner']) ? 2 : 0) | (in_array('execute', $data['owner']) ? 1 : 0);
|
$owner = (in_array('read', $data['owner']) ? 4 : 0) | (in_array('write', $data['owner']) ? 2 : 0) | (in_array('execute', $data['owner']) ? 1 : 0);
|
||||||
$group = (in_array('read', $data['group']) ? 4 : 0) | (in_array('write', $data['group']) ? 2 : 0) | (in_array('execute', $data['group']) ? 1 : 0);
|
$group = (in_array('read', $data['group']) ? 4 : 0) | (in_array('write', $data['group']) ? 2 : 0) | (in_array('execute', $data['group']) ? 1 : 0);
|
||||||
$public = (in_array('read', $data['public']) ? 4 : 0) | (in_array('write', $data['public']) ? 2 : 0) | (in_array('execute', $data['public']) ? 1 : 0);
|
$public = (in_array('read', $data['public']) ? 4 : 0) | (in_array('write', $data['public']) ? 2 : 0) | (in_array('execute', $data['public']) ? 1 : 0);
|
||||||
|
|
||||||
$mode = $owner . $group . $public;
|
$mode = $owner . $group . $public;
|
||||||
|
|
||||||
// @phpstan-ignore-next-line
|
$fileRepository
|
||||||
app(DaemonFileRepository::class)
|
|
||||||
->setServer($server)
|
->setServer($server)
|
||||||
->chmodFiles($this->path, [['file' => $file->name, 'mode' => $mode]]);
|
->chmodFiles($this->path, [['file' => $file->name, 'mode' => $mode]]);
|
||||||
|
|
||||||
@ -282,9 +280,8 @@ class ListFiles extends ListRecords
|
|||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_ARCHIVE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_ARCHIVE, $server))
|
||||||
->label('Archive')
|
->label('Archive')
|
||||||
->icon('tabler-archive')
|
->icon('tabler-archive')
|
||||||
->action(function (File $file) use ($server) {
|
->action(function (File $file, DaemonFileRepository $fileRepository) use ($server) {
|
||||||
// @phpstan-ignore-next-line
|
$fileRepository
|
||||||
app(DaemonFileRepository::class)
|
|
||||||
->setServer($server)
|
->setServer($server)
|
||||||
->compressFiles($this->path, [$file->name]);
|
->compressFiles($this->path, [$file->name]);
|
||||||
|
|
||||||
@ -305,9 +302,8 @@ class ListFiles extends ListRecords
|
|||||||
->label('Unarchive')
|
->label('Unarchive')
|
||||||
->icon('tabler-archive')
|
->icon('tabler-archive')
|
||||||
->visible(fn (File $file) => $file->isArchive())
|
->visible(fn (File $file) => $file->isArchive())
|
||||||
->action(function (File $file) use ($server) {
|
->action(function (File $file, DaemonFileRepository $fileRepository) use ($server) {
|
||||||
// @phpstan-ignore-next-line
|
$fileRepository
|
||||||
app(DaemonFileRepository::class)
|
|
||||||
->setServer($server)
|
->setServer($server)
|
||||||
->decompressFile($this->path, $file->name);
|
->decompressFile($this->path, $file->name);
|
||||||
|
|
||||||
@ -331,9 +327,8 @@ class ListFiles extends ListRecords
|
|||||||
->requiresConfirmation()
|
->requiresConfirmation()
|
||||||
->modalDescription(fn (File $file) => $file->name)
|
->modalDescription(fn (File $file) => $file->name)
|
||||||
->modalHeading('Delete file?')
|
->modalHeading('Delete file?')
|
||||||
->action(function (File $file) use ($server) {
|
->action(function (File $file, DaemonFileRepository $fileRepository) use ($server) {
|
||||||
// @phpstan-ignore-next-line
|
$fileRepository
|
||||||
app(DaemonFileRepository::class)
|
|
||||||
->setServer($server)
|
->setServer($server)
|
||||||
->deleteFiles($this->path, [$file->name]);
|
->deleteFiles($this->path, [$file->name]);
|
||||||
|
|
||||||
@ -357,14 +352,12 @@ class ListFiles extends ListRecords
|
|||||||
Placeholder::make('new_location')
|
Placeholder::make('new_location')
|
||||||
->content(fn (Get $get) => resolve_path('./' . join_paths($this->path, $get('location') ?? ''))),
|
->content(fn (Get $get) => resolve_path('./' . join_paths($this->path, $get('location') ?? ''))),
|
||||||
])
|
])
|
||||||
->action(function (Collection $files, $data) use ($server) {
|
->action(function (Collection $files, $data, DaemonFileRepository $fileRepository) use ($server) {
|
||||||
$location = resolve_path(join_paths($this->path, $data['location']));
|
$location = resolve_path(join_paths($this->path, $data['location']));
|
||||||
|
|
||||||
// @phpstan-ignore-next-line
|
// @phpstan-ignore-next-line
|
||||||
$files = $files->map(fn ($file) => ['to' => $location, 'from' => $file->name])->toArray();
|
$files = $files->map(fn ($file) => ['to' => $location, 'from' => $file->name])->toArray();
|
||||||
|
$fileRepository
|
||||||
// @phpstan-ignore-next-line
|
|
||||||
app(DaemonFileRepository::class)
|
|
||||||
->setServer($server)
|
->setServer($server)
|
||||||
->renameFiles($this->path, $files);
|
->renameFiles($this->path, $files);
|
||||||
|
|
||||||
@ -380,12 +373,11 @@ class ListFiles extends ListRecords
|
|||||||
}),
|
}),
|
||||||
BulkAction::make('archive')
|
BulkAction::make('archive')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_ARCHIVE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_ARCHIVE, $server))
|
||||||
->action(function (Collection $files) use ($server) {
|
->action(function (Collection $files, DaemonFileRepository $fileRepository) use ($server) {
|
||||||
// @phpstan-ignore-next-line
|
// @phpstan-ignore-next-line
|
||||||
$files = $files->map(fn ($file) => $file->name)->toArray();
|
$files = $files->map(fn ($file) => $file->name)->toArray();
|
||||||
|
|
||||||
// @phpstan-ignore-next-line
|
$fileRepository
|
||||||
app(DaemonFileRepository::class)
|
|
||||||
->setServer($server)
|
->setServer($server)
|
||||||
->compressFiles($this->path, $files);
|
->compressFiles($this->path, $files);
|
||||||
|
|
||||||
@ -403,12 +395,10 @@ class ListFiles extends ListRecords
|
|||||||
}),
|
}),
|
||||||
DeleteBulkAction::make()
|
DeleteBulkAction::make()
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_DELETE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_DELETE, $server))
|
||||||
->action(function (Collection $files) use ($server) {
|
->action(function (Collection $files, DaemonFileRepository $fileRepository) use ($server) {
|
||||||
// @phpstan-ignore-next-line
|
// @phpstan-ignore-next-line
|
||||||
$files = $files->map(fn ($file) => $file->name)->toArray();
|
$files = $files->map(fn ($file) => $file->name)->toArray();
|
||||||
|
$fileRepository
|
||||||
// @phpstan-ignore-next-line
|
|
||||||
app(DaemonFileRepository::class)
|
|
||||||
->setServer($server)
|
->setServer($server)
|
||||||
->deleteFiles($this->path, $files);
|
->deleteFiles($this->path, $files);
|
||||||
|
|
||||||
@ -438,9 +428,8 @@ class ListFiles extends ListRecords
|
|||||||
->color('gray')
|
->color('gray')
|
||||||
->keyBindings('')
|
->keyBindings('')
|
||||||
->modalSubmitActionLabel('Create')
|
->modalSubmitActionLabel('Create')
|
||||||
->action(function ($data) use ($server) {
|
->action(function ($data, DaemonFileRepository $fileRepository) use ($server) {
|
||||||
// @phpstan-ignore-next-line
|
$fileRepository
|
||||||
app(DaemonFileRepository::class)
|
|
||||||
->setServer($server)
|
->setServer($server)
|
||||||
->putContent(join_paths($this->path, $data['name']), $data['editor'] ?? '');
|
->putContent(join_paths($this->path, $data['name']), $data['editor'] ?? '');
|
||||||
|
|
||||||
@ -467,9 +456,8 @@ class ListFiles extends ListRecords
|
|||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_CREATE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_CREATE, $server))
|
||||||
->label('New Folder')
|
->label('New Folder')
|
||||||
->color('gray')
|
->color('gray')
|
||||||
->action(function ($data) use ($server) {
|
->action(function ($data, DaemonFileRepository $fileRepository) use ($server) {
|
||||||
// @phpstan-ignore-next-line
|
$fileRepository
|
||||||
app(DaemonFileRepository::class)
|
|
||||||
->setServer($server)
|
->setServer($server)
|
||||||
->createDirectory($data['name'], $this->path);
|
->createDirectory($data['name'], $this->path);
|
||||||
|
|
||||||
@ -485,12 +473,11 @@ class ListFiles extends ListRecords
|
|||||||
HeaderAction::make('upload')
|
HeaderAction::make('upload')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_CREATE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_CREATE, $server))
|
||||||
->label('Upload')
|
->label('Upload')
|
||||||
->action(function ($data) use ($server) {
|
->action(function ($data, DaemonFileRepository $fileRepository) use ($server) {
|
||||||
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) {
|
||||||
// @phpstan-ignore-next-line
|
$fileRepository
|
||||||
app(DaemonFileRepository::class)
|
|
||||||
->setServer($server)
|
->setServer($server)
|
||||||
->putContent(join_paths($this->path, $file->getClientOriginalName()), $file->getContent());
|
->putContent(join_paths($this->path, $file->getClientOriginalName()), $file->getContent());
|
||||||
|
|
||||||
@ -500,8 +487,7 @@ class ListFiles extends ListRecords
|
|||||||
->log();
|
->log();
|
||||||
}
|
}
|
||||||
} elseif ($data['url'] !== null) {
|
} elseif ($data['url'] !== null) {
|
||||||
// @phpstan-ignore-next-line
|
$fileRepository
|
||||||
app(DaemonFileRepository::class)
|
|
||||||
->setServer($server)
|
->setServer($server)
|
||||||
->pull($data['url'], $this->path);
|
->pull($data['url'], $this->path);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user