Add archive extension selection (#1828)

This commit is contained in:
Charles 2025-10-24 12:39:30 -04:00 committed by GitHub
parent 8e006ac32d
commit e6bd6e416f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 46 additions and 12 deletions

View File

@ -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'])

View File

@ -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')

View File

@ -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',
];
}
}

View File

@ -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();
}

View File

@ -46,6 +46,7 @@ return [
'title' => 'Archive',
'archive_name' => 'Archive Name',
'notification' => 'Archive Created',
'extension' => 'Extension',
],
'unarchive' => [
'title' => 'Unarchive',