mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 00:34: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\Client\ConnectionException;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
use Illuminate\Routing\Route;
|
use Illuminate\Routing\Route;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Facades\Route as RouteFacade;
|
use Illuminate\Support\Facades\Route as RouteFacade;
|
||||||
use Livewire\Attributes\Locked;
|
use Livewire\Attributes\Locked;
|
||||||
|
|
||||||
@ -295,16 +296,24 @@ class ListFiles extends ListRecords
|
|||||||
->disabled($this->isDisabled)
|
->disabled($this->isDisabled)
|
||||||
->label('Archive')
|
->label('Archive')
|
||||||
->icon('tabler-archive')
|
->icon('tabler-archive')
|
||||||
->action(function (File $file) {
|
->form([
|
||||||
$this->getDaemonFileRepository()->compressFiles($this->path, [$file->name]);
|
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')
|
Activity::event('server:file.compress')
|
||||||
|
->property('name', $archive['name'])
|
||||||
->property('directory', $this->path)
|
->property('directory', $this->path)
|
||||||
->property('files', [$file->name])
|
->property('files', [$file->name])
|
||||||
->log();
|
->log();
|
||||||
|
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Archive created')
|
->title('Archive created')
|
||||||
|
->body($archive['name'])
|
||||||
->success()
|
->success()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
@ -383,18 +392,26 @@ 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))
|
||||||
->disabled($this->isDisabled)
|
->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();
|
$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')
|
Activity::event('server:file.compress')
|
||||||
|
->property('name', $archive['name'])
|
||||||
->property('directory', $this->path)
|
->property('directory', $this->path)
|
||||||
->property('files', $files)
|
->property('files', $files)
|
||||||
->log();
|
->log();
|
||||||
|
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Archive created')
|
->title('Archive created')
|
||||||
|
->body($archive['name'])
|
||||||
->success()
|
->success()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
|
@ -210,10 +210,12 @@ 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')
|
||||||
);
|
);
|
||||||
|
|
||||||
Activity::event('server:file.compress')
|
Activity::event('server:file.compress')
|
||||||
|
->property('name', $file['name'])
|
||||||
->property('directory', $request->input('root'))
|
->property('directory', $request->input('root'))
|
||||||
->property('files', $request->input('files'))
|
->property('files', $request->input('files'))
|
||||||
->log();
|
->log();
|
||||||
|
@ -21,6 +21,7 @@ class CompressFilesRequest extends ClientApiRequest
|
|||||||
'root' => 'sometimes|nullable|string',
|
'root' => 'sometimes|nullable|string',
|
||||||
'files' => 'required|array',
|
'files' => 'required|array',
|
||||||
'files.*' => 'string',
|
'files.*' => 'string',
|
||||||
|
'name' => 'sometimes|nullable|string',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ class DaemonFileRepository extends DaemonRepository
|
|||||||
*
|
*
|
||||||
* @throws ConnectionException
|
* @throws ConnectionException
|
||||||
*/
|
*/
|
||||||
public function compressFiles(?string $root, array $files): array
|
public function compressFiles(?string $root, array $files, ?string $name): 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
|
||||||
@ -148,6 +148,7 @@ class DaemonFileRepository extends DaemonRepository
|
|||||||
[
|
[
|
||||||
'root' => $root ?? '/',
|
'root' => $root ?? '/',
|
||||||
'files' => $files,
|
'files' => $files,
|
||||||
|
'name' => $name ?? '',
|
||||||
]
|
]
|
||||||
)->json();
|
)->json();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user