mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-19 21:04:44 +02:00
Allow user to choose archive
name in FileManager
(#1206)
* Allow user to choose `archive` name in `FileManager` * Rollback `file.compress` activity translation
This commit is contained in:
parent
b9d4773bd7
commit
566e7c1b24
@ -40,6 +40,7 @@ use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Route as RouteFacade;
|
||||
use Livewire\Attributes\Locked;
|
||||
|
||||
@ -295,16 +296,24 @@ class ListFiles extends ListRecords
|
||||
->disabled($this->isDisabled)
|
||||
->label('Archive')
|
||||
->icon('tabler-archive')
|
||||
->action(function (File $file) {
|
||||
$this->getDaemonFileRepository()->compressFiles($this->path, [$file->name]);
|
||||
->form([
|
||||
TextInput::make('name')
|
||||
->label('Archive name')
|
||||
->placeholder(fn () => 'archive-' . str(Carbon::now()->toRfc3339String())->replace(':', '')->before('+0000') . 'Z')
|
||||
->suffix('.tar.gz'),
|
||||
])
|
||||
->action(function ($data, File $file) {
|
||||
$archive = $this->getDaemonFileRepository()->compressFiles($this->path, [$file->name], $data['name']);
|
||||
|
||||
Activity::event('server:file.compress')
|
||||
->property('name', $archive['name'])
|
||||
->property('directory', $this->path)
|
||||
->property('files', [$file->name])
|
||||
->log();
|
||||
|
||||
Notification::make()
|
||||
->title('Archive created')
|
||||
->body($archive['name'])
|
||||
->success()
|
||||
->send();
|
||||
|
||||
@ -383,18 +392,26 @@ class ListFiles extends ListRecords
|
||||
BulkAction::make('archive')
|
||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_ARCHIVE, $server))
|
||||
->disabled($this->isDisabled)
|
||||
->action(function (Collection $files) {
|
||||
->form([
|
||||
TextInput::make('name')
|
||||
->label('Archive name')
|
||||
->placeholder(fn () => 'archive-' . str(Carbon::now()->toRfc3339String())->replace(':', '')->before('+0000') . 'Z')
|
||||
->suffix('.tar.gz'),
|
||||
])
|
||||
->action(function ($data, Collection $files) {
|
||||
$files = $files->map(fn ($file) => $file['name'])->toArray();
|
||||
|
||||
$this->getDaemonFileRepository()->compressFiles($this->path, $files);
|
||||
$archive = $this->getDaemonFileRepository()->compressFiles($this->path, $files, $data['name']);
|
||||
|
||||
Activity::event('server:file.compress')
|
||||
->property('name', $archive['name'])
|
||||
->property('directory', $this->path)
|
||||
->property('files', $files)
|
||||
->log();
|
||||
|
||||
Notification::make()
|
||||
->title('Archive created')
|
||||
->body($archive['name'])
|
||||
->success()
|
||||
->send();
|
||||
|
||||
|
@ -210,10 +210,12 @@ class FileController extends ClientApiController
|
||||
{
|
||||
$file = $this->fileRepository->setServer($server)->compressFiles(
|
||||
$request->input('root'),
|
||||
$request->input('files')
|
||||
$request->input('files'),
|
||||
$request->input('name')
|
||||
);
|
||||
|
||||
Activity::event('server:file.compress')
|
||||
->property('name', $file['name'])
|
||||
->property('directory', $request->input('root'))
|
||||
->property('files', $request->input('files'))
|
||||
->log();
|
||||
|
@ -21,6 +21,7 @@ class CompressFilesRequest extends ClientApiRequest
|
||||
'root' => 'sometimes|nullable|string',
|
||||
'files' => 'required|array',
|
||||
'files.*' => 'string',
|
||||
'name' => 'sometimes|nullable|string',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ class DaemonFileRepository extends DaemonRepository
|
||||
*
|
||||
* @throws ConnectionException
|
||||
*/
|
||||
public function compressFiles(?string $root, array $files): array
|
||||
public function compressFiles(?string $root, array $files, ?string $name): array
|
||||
{
|
||||
return $this->getHttpClient()
|
||||
// Wait for up to 15 minutes for the archive to be completed when calling this endpoint
|
||||
@ -148,6 +148,7 @@ class DaemonFileRepository extends DaemonRepository
|
||||
[
|
||||
'root' => $root ?? '/',
|
||||
'files' => $files,
|
||||
'name' => $name ?? '',
|
||||
]
|
||||
)->json();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user