From e6bd6e416f78e828d851eff3a57760a6fbdb56e1 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 24 Oct 2025 12:39:30 -0400 Subject: [PATCH] Add archive extension selection (#1828) --- .../Resources/Files/Pages/ListFiles.php | 50 +++++++++++++++---- .../Api/Client/Servers/FileController.php | 3 +- .../Servers/Files/CompressFilesRequest.php | 1 + .../Daemon/DaemonFileRepository.php | 3 +- lang/en/server/file.php | 1 + 5 files changed, 46 insertions(+), 12 deletions(-) diff --git a/app/Filament/Server/Resources/Files/Pages/ListFiles.php b/app/Filament/Server/Resources/Files/Pages/ListFiles.php index 3d1460be7..b8dee2b2f 100644 --- a/app/Filament/Server/Resources/Files/Pages/ListFiles.php +++ b/app/Filament/Server/Resources/Files/Pages/ListFiles.php @@ -26,12 +26,14 @@ use Filament\Facades\Filament; use Filament\Forms\Components\CheckboxList; use Filament\Forms\Components\CodeEditor; use Filament\Forms\Components\FileUpload; +use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Infolists\Components\TextEntry; use Filament\Notifications\Notification; use Filament\Panel; use Filament\Resources\Pages\ListRecords; use Filament\Resources\Pages\PageRegistration; +use Filament\Schemas\Components\Grid; use Filament\Schemas\Components\Tabs; use Filament\Schemas\Components\Tabs\Tab; use Filament\Schemas\Components\Utilities\Get; @@ -297,13 +299,27 @@ class ListFiles extends ListRecords ->label(trans('server/file.actions.archive.title')) ->icon('tabler-archive')->iconSize(IconSize::Large) ->schema([ - TextInput::make('name') - ->label(trans('server/file.actions.archive.archive_name')) - ->placeholder(fn () => 'archive-' . str(Carbon::now()->toRfc3339String())->replace(':', '')->before('+0000') . 'Z') - ->suffix('.tar.gz'), + Grid::make(3) + ->schema([ + TextInput::make('name') + ->label(trans('server/file.actions.archive.archive_name')) + ->placeholder(fn () => 'archive-' . str(Carbon::now()->toRfc3339String())->replace(':', '')->before('+0000') . 'Z') + ->columnSpan(2), + Select::make('extension') + ->label(trans('server/file.actions.archive.extension')) + ->selectablePlaceholder(false) + ->native(false) + ->options([ + 'tar.gz' => 'tar.gz', + 'zip' => 'zip', + 'tar.bz2' => 'tar.bz2', + 'tar.xz' => 'tar.xz', + ]) + ->columnSpan(1), + ]), ]) ->action(function ($data, File $file) { - $archive = $this->getDaemonFileRepository()->compressFiles($this->path, [$file->name], $data['name']); + $archive = $this->getDaemonFileRepository()->compressFiles($this->path, [$file->name], $data['name'], $data['extension']); Activity::event('server:file.compress') ->property('name', $archive['name']) @@ -392,15 +408,29 @@ class ListFiles extends ListRecords BulkAction::make('archive') ->authorize(fn () => user()?->can(Permission::ACTION_FILE_ARCHIVE, $server)) ->schema([ - TextInput::make('name') - ->label(trans('server/file.actions.archive.archive_name')) - ->placeholder(fn () => 'archive-' . str(Carbon::now()->toRfc3339String())->replace(':', '')->before('+0000') . 'Z') - ->suffix('.tar.gz'), + Grid::make(3) + ->schema([ + TextInput::make('name') + ->label(trans('server/file.actions.archive.archive_name')) + ->placeholder(fn () => 'archive-' . str(Carbon::now()->toRfc3339String())->replace(':', '')->before('+0000') . 'Z') + ->columnSpan(2), + Select::make('extension') + ->label(trans('server/file.actions.archive.extension')) + ->selectablePlaceholder(false) + ->native(false) + ->options([ + 'tar.gz' => 'tar.gz', + 'zip' => 'zip', + 'tar.bz2' => 'tar.bz2', + 'tar.xz' => 'tar.xz', + ]) + ->columnSpan(1), + ]), ]) ->action(function ($data, Collection $files) { $files = $files->map(fn ($file) => $file['name'])->toArray(); - $archive = $this->getDaemonFileRepository()->compressFiles($this->path, $files, $data['name']); + $archive = $this->getDaemonFileRepository()->compressFiles($this->path, $files, $data['name'], $data['extension']); Activity::event('server:file.compress') ->property('name', $archive['name']) diff --git a/app/Http/Controllers/Api/Client/Servers/FileController.php b/app/Http/Controllers/Api/Client/Servers/FileController.php index ba1088e95..f9da65caa 100644 --- a/app/Http/Controllers/Api/Client/Servers/FileController.php +++ b/app/Http/Controllers/Api/Client/Servers/FileController.php @@ -212,7 +212,8 @@ class FileController extends ClientApiController $file = $this->fileRepository->setServer($server)->compressFiles( $request->input('root'), $request->input('files'), - $request->input('name') + $request->input('name'), + $request->input('extension') ); Activity::event('server:file.compress') diff --git a/app/Http/Requests/Api/Client/Servers/Files/CompressFilesRequest.php b/app/Http/Requests/Api/Client/Servers/Files/CompressFilesRequest.php index e7e0e3578..ca3993718 100644 --- a/app/Http/Requests/Api/Client/Servers/Files/CompressFilesRequest.php +++ b/app/Http/Requests/Api/Client/Servers/Files/CompressFilesRequest.php @@ -22,6 +22,7 @@ class CompressFilesRequest extends ClientApiRequest 'files' => 'required|array', 'files.*' => 'string', 'name' => 'sometimes|nullable|string', + 'extension' => 'sometimes|in:zip,tgz,tar.gz,txz,tar.xz,tbz2,tar.bz2', ]; } } diff --git a/app/Repositories/Daemon/DaemonFileRepository.php b/app/Repositories/Daemon/DaemonFileRepository.php index 2f4e7b04d..8cc2e4da0 100644 --- a/app/Repositories/Daemon/DaemonFileRepository.php +++ b/app/Repositories/Daemon/DaemonFileRepository.php @@ -153,7 +153,7 @@ class DaemonFileRepository extends DaemonRepository * * @throws ConnectionException */ - public function compressFiles(?string $root, array $files, ?string $name): array + public function compressFiles(?string $root, array $files, ?string $name, ?string $extension): array { return $this->getHttpClient() // Wait for up to 15 minutes for the archive to be completed when calling this endpoint @@ -164,6 +164,7 @@ class DaemonFileRepository extends DaemonRepository 'root' => $root ?? '/', 'files' => $files, 'name' => $name ?? '', + 'extension' => $extension ?? '', ] )->json(); } diff --git a/lang/en/server/file.php b/lang/en/server/file.php index e0723271c..dc936a477 100644 --- a/lang/en/server/file.php +++ b/lang/en/server/file.php @@ -46,6 +46,7 @@ return [ 'title' => 'Archive', 'archive_name' => 'Archive Name', 'notification' => 'Archive Created', + 'extension' => 'Extension', ], 'unarchive' => [ 'title' => 'Unarchive',