mirror of
https://github.com/pelican-dev/panel.git
synced 2025-10-30 04:06:52 +01:00
Add archive extension selection (#1828)
This commit is contained in:
parent
8e006ac32d
commit
e6bd6e416f
@ -26,12 +26,14 @@ use Filament\Facades\Filament;
|
|||||||
use Filament\Forms\Components\CheckboxList;
|
use Filament\Forms\Components\CheckboxList;
|
||||||
use Filament\Forms\Components\CodeEditor;
|
use Filament\Forms\Components\CodeEditor;
|
||||||
use Filament\Forms\Components\FileUpload;
|
use Filament\Forms\Components\FileUpload;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Infolists\Components\TextEntry;
|
use Filament\Infolists\Components\TextEntry;
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Panel;
|
use Filament\Panel;
|
||||||
use Filament\Resources\Pages\ListRecords;
|
use Filament\Resources\Pages\ListRecords;
|
||||||
use Filament\Resources\Pages\PageRegistration;
|
use Filament\Resources\Pages\PageRegistration;
|
||||||
|
use Filament\Schemas\Components\Grid;
|
||||||
use Filament\Schemas\Components\Tabs;
|
use Filament\Schemas\Components\Tabs;
|
||||||
use Filament\Schemas\Components\Tabs\Tab;
|
use Filament\Schemas\Components\Tabs\Tab;
|
||||||
use Filament\Schemas\Components\Utilities\Get;
|
use Filament\Schemas\Components\Utilities\Get;
|
||||||
@ -297,13 +299,27 @@ class ListFiles extends ListRecords
|
|||||||
->label(trans('server/file.actions.archive.title'))
|
->label(trans('server/file.actions.archive.title'))
|
||||||
->icon('tabler-archive')->iconSize(IconSize::Large)
|
->icon('tabler-archive')->iconSize(IconSize::Large)
|
||||||
->schema([
|
->schema([
|
||||||
TextInput::make('name')
|
Grid::make(3)
|
||||||
->label(trans('server/file.actions.archive.archive_name'))
|
->schema([
|
||||||
->placeholder(fn () => 'archive-' . str(Carbon::now()->toRfc3339String())->replace(':', '')->before('+0000') . 'Z')
|
TextInput::make('name')
|
||||||
->suffix('.tar.gz'),
|
->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) {
|
->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')
|
Activity::event('server:file.compress')
|
||||||
->property('name', $archive['name'])
|
->property('name', $archive['name'])
|
||||||
@ -392,15 +408,29 @@ class ListFiles extends ListRecords
|
|||||||
BulkAction::make('archive')
|
BulkAction::make('archive')
|
||||||
->authorize(fn () => user()?->can(Permission::ACTION_FILE_ARCHIVE, $server))
|
->authorize(fn () => user()?->can(Permission::ACTION_FILE_ARCHIVE, $server))
|
||||||
->schema([
|
->schema([
|
||||||
TextInput::make('name')
|
Grid::make(3)
|
||||||
->label(trans('server/file.actions.archive.archive_name'))
|
->schema([
|
||||||
->placeholder(fn () => 'archive-' . str(Carbon::now()->toRfc3339String())->replace(':', '')->before('+0000') . 'Z')
|
TextInput::make('name')
|
||||||
->suffix('.tar.gz'),
|
->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) {
|
->action(function ($data, Collection $files) {
|
||||||
$files = $files->map(fn ($file) => $file['name'])->toArray();
|
$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')
|
Activity::event('server:file.compress')
|
||||||
->property('name', $archive['name'])
|
->property('name', $archive['name'])
|
||||||
|
|||||||
@ -212,7 +212,8 @@ class FileController extends ClientApiController
|
|||||||
$file = $this->fileRepository->setServer($server)->compressFiles(
|
$file = $this->fileRepository->setServer($server)->compressFiles(
|
||||||
$request->input('root'),
|
$request->input('root'),
|
||||||
$request->input('files'),
|
$request->input('files'),
|
||||||
$request->input('name')
|
$request->input('name'),
|
||||||
|
$request->input('extension')
|
||||||
);
|
);
|
||||||
|
|
||||||
Activity::event('server:file.compress')
|
Activity::event('server:file.compress')
|
||||||
|
|||||||
@ -22,6 +22,7 @@ class CompressFilesRequest extends ClientApiRequest
|
|||||||
'files' => 'required|array',
|
'files' => 'required|array',
|
||||||
'files.*' => 'string',
|
'files.*' => 'string',
|
||||||
'name' => 'sometimes|nullable|string',
|
'name' => 'sometimes|nullable|string',
|
||||||
|
'extension' => 'sometimes|in:zip,tgz,tar.gz,txz,tar.xz,tbz2,tar.bz2',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -153,7 +153,7 @@ class DaemonFileRepository extends DaemonRepository
|
|||||||
*
|
*
|
||||||
* @throws ConnectionException
|
* @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()
|
return $this->getHttpClient()
|
||||||
// Wait for up to 15 minutes for the archive to be completed when calling this endpoint
|
// 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 ?? '/',
|
'root' => $root ?? '/',
|
||||||
'files' => $files,
|
'files' => $files,
|
||||||
'name' => $name ?? '',
|
'name' => $name ?? '',
|
||||||
|
'extension' => $extension ?? '',
|
||||||
]
|
]
|
||||||
)->json();
|
)->json();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,6 +46,7 @@ return [
|
|||||||
'title' => 'Archive',
|
'title' => 'Archive',
|
||||||
'archive_name' => 'Archive Name',
|
'archive_name' => 'Archive Name',
|
||||||
'notification' => 'Archive Created',
|
'notification' => 'Archive Created',
|
||||||
|
'extension' => 'Extension',
|
||||||
],
|
],
|
||||||
'unarchive' => [
|
'unarchive' => [
|
||||||
'title' => 'Unarchive',
|
'title' => 'Unarchive',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user