mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 00:34:44 +02:00
Catch DaemonFileRepository
& show Alert (#1129)
* Catch `DaemonFileRepository` Co-authored-by: notCharles <charles@pelican.dev> * Pint --------- Co-authored-by: notCharles <charles@pelican.dev>
This commit is contained in:
parent
2dbb9a5f9b
commit
29f3defc73
@ -12,6 +12,7 @@ use App\Models\Server;
|
|||||||
use App\Repositories\Daemon\DaemonFileRepository;
|
use App\Repositories\Daemon\DaemonFileRepository;
|
||||||
use App\Filament\Components\Tables\Columns\BytesColumn;
|
use App\Filament\Components\Tables\Columns\BytesColumn;
|
||||||
use App\Filament\Components\Tables\Columns\DateTimeColumn;
|
use App\Filament\Components\Tables\Columns\DateTimeColumn;
|
||||||
|
use App\Livewire\AlertBanner;
|
||||||
use Filament\Actions\Action as HeaderAction;
|
use Filament\Actions\Action as HeaderAction;
|
||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
use Filament\Forms\Components\CheckboxList;
|
use Filament\Forms\Components\CheckboxList;
|
||||||
@ -36,6 +37,7 @@ use Filament\Tables\Actions\EditAction;
|
|||||||
use Filament\Tables\Columns\TextColumn;
|
use Filament\Tables\Columns\TextColumn;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
use Illuminate\Http\Client\ConnectionException;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
use Illuminate\Routing\Route;
|
use Illuminate\Routing\Route;
|
||||||
use Illuminate\Support\Facades\Route as RouteFacade;
|
use Illuminate\Support\Facades\Route as RouteFacade;
|
||||||
@ -50,10 +52,19 @@ class ListFiles extends ListRecords
|
|||||||
|
|
||||||
private DaemonFileRepository $fileRepository;
|
private DaemonFileRepository $fileRepository;
|
||||||
|
|
||||||
|
private bool $isDisabled = false;
|
||||||
|
|
||||||
public function mount(?string $path = null): void
|
public function mount(?string $path = null): void
|
||||||
{
|
{
|
||||||
parent::mount();
|
parent::mount();
|
||||||
$this->path = $path ?? '/';
|
$this->path = $path ?? '/';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->getDaemonFileRepository()->getDirectory('/');
|
||||||
|
} catch (ConnectionException) {
|
||||||
|
$this->isDisabled = true;
|
||||||
|
$this->getFailureNotification();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBreadcrumbs(): array
|
public function getBreadcrumbs(): array
|
||||||
@ -113,18 +124,21 @@ class ListFiles extends ListRecords
|
|||||||
->actions([
|
->actions([
|
||||||
Action::make('view')
|
Action::make('view')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_READ, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_READ, $server))
|
||||||
|
->disabled($this->isDisabled)
|
||||||
->label('Open')
|
->label('Open')
|
||||||
->icon('tabler-eye')
|
->icon('tabler-eye')
|
||||||
->visible(fn (File $file) => $file->is_directory)
|
->visible(fn (File $file) => $file->is_directory)
|
||||||
->url(fn (File $file) => self::getUrl(['path' => join_paths($this->path, $file->name)])),
|
->url(fn (File $file) => self::getUrl(['path' => join_paths($this->path, $file->name)])),
|
||||||
EditAction::make('edit')
|
EditAction::make('edit')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_READ_CONTENT, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_READ_CONTENT, $server))
|
||||||
|
->disabled($this->isDisabled)
|
||||||
->icon('tabler-edit')
|
->icon('tabler-edit')
|
||||||
->visible(fn (File $file) => $file->canEdit())
|
->visible(fn (File $file) => $file->canEdit())
|
||||||
->url(fn (File $file) => EditFiles::getUrl(['path' => join_paths($this->path, $file->name)])),
|
->url(fn (File $file) => EditFiles::getUrl(['path' => join_paths($this->path, $file->name)])),
|
||||||
ActionGroup::make([
|
ActionGroup::make([
|
||||||
Action::make('rename')
|
Action::make('rename')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_UPDATE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_UPDATE, $server))
|
||||||
|
->disabled($this->isDisabled)
|
||||||
->label('Rename')
|
->label('Rename')
|
||||||
->icon('tabler-forms')
|
->icon('tabler-forms')
|
||||||
->form([
|
->form([
|
||||||
@ -136,8 +150,7 @@ class ListFiles extends ListRecords
|
|||||||
->action(function ($data, File $file) {
|
->action(function ($data, File $file) {
|
||||||
$files = [['to' => $data['name'], 'from' => $file->name]];
|
$files = [['to' => $data['name'], 'from' => $file->name]];
|
||||||
|
|
||||||
$this->getDaemonFileRepository()
|
$this->getDaemonFileRepository()->renameFiles($this->path, $files);
|
||||||
->renameFiles($this->path, $files);
|
|
||||||
|
|
||||||
Activity::event('server:file.rename')
|
Activity::event('server:file.rename')
|
||||||
->property('directory', $this->path)
|
->property('directory', $this->path)
|
||||||
@ -154,12 +167,12 @@ class ListFiles extends ListRecords
|
|||||||
}),
|
}),
|
||||||
Action::make('copy')
|
Action::make('copy')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_CREATE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_CREATE, $server))
|
||||||
|
->disabled($this->isDisabled)
|
||||||
->label('Copy')
|
->label('Copy')
|
||||||
->icon('tabler-copy')
|
->icon('tabler-copy')
|
||||||
->visible(fn (File $file) => $file->is_file)
|
->visible(fn (File $file) => $file->is_file)
|
||||||
->action(function (File $file) {
|
->action(function (File $file) {
|
||||||
$this->getDaemonFileRepository()
|
$this->getDaemonFileRepository()->copyFile(join_paths($this->path, $file->name));
|
||||||
->copyFile(join_paths($this->path, $file->name));
|
|
||||||
|
|
||||||
Activity::event('server:file.copy')
|
Activity::event('server:file.copy')
|
||||||
->property('file', join_paths($this->path, $file->name))
|
->property('file', join_paths($this->path, $file->name))
|
||||||
@ -174,12 +187,14 @@ class ListFiles extends ListRecords
|
|||||||
}),
|
}),
|
||||||
Action::make('download')
|
Action::make('download')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_READ_CONTENT, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_READ_CONTENT, $server))
|
||||||
|
->disabled($this->isDisabled)
|
||||||
->label('Download')
|
->label('Download')
|
||||||
->icon('tabler-download')
|
->icon('tabler-download')
|
||||||
->visible(fn (File $file) => $file->is_file)
|
->visible(fn (File $file) => $file->is_file)
|
||||||
->url(fn (File $file) => DownloadFiles::getUrl(['path' => join_paths($this->path, $file->name)]), true),
|
->url(fn (File $file) => DownloadFiles::getUrl(['path' => join_paths($this->path, $file->name)]), true),
|
||||||
Action::make('move')
|
Action::make('move')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_UPDATE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_UPDATE, $server))
|
||||||
|
->disabled($this->isDisabled)
|
||||||
->label('Move')
|
->label('Move')
|
||||||
->icon('tabler-replace')
|
->icon('tabler-replace')
|
||||||
->form([
|
->form([
|
||||||
@ -195,8 +210,7 @@ class ListFiles extends ListRecords
|
|||||||
$location = rtrim($data['location'], '/');
|
$location = rtrim($data['location'], '/');
|
||||||
$files = [['to' => join_paths($location, $file->name), 'from' => $file->name]];
|
$files = [['to' => join_paths($location, $file->name), 'from' => $file->name]];
|
||||||
|
|
||||||
$this->getDaemonFileRepository()
|
$this->getDaemonFileRepository()->renameFiles($this->path, $files);
|
||||||
->renameFiles($this->path, $files);
|
|
||||||
|
|
||||||
$oldLocation = join_paths($this->path, $file->name);
|
$oldLocation = join_paths($this->path, $file->name);
|
||||||
$newLocation = resolve_path(join_paths($this->path, $location, $file->name));
|
$newLocation = resolve_path(join_paths($this->path, $location, $file->name));
|
||||||
@ -216,6 +230,7 @@ class ListFiles extends ListRecords
|
|||||||
}),
|
}),
|
||||||
Action::make('permissions')
|
Action::make('permissions')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_UPDATE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_UPDATE, $server))
|
||||||
|
->disabled($this->isDisabled)
|
||||||
->label('Permissions')
|
->label('Permissions')
|
||||||
->icon('tabler-license')
|
->icon('tabler-license')
|
||||||
->form([
|
->form([
|
||||||
@ -263,8 +278,7 @@ class ListFiles extends ListRecords
|
|||||||
|
|
||||||
$mode = $owner . $group . $public;
|
$mode = $owner . $group . $public;
|
||||||
|
|
||||||
$this->getDaemonFileRepository()
|
$this->getDaemonFileRepository()->chmodFiles($this->path, [['file' => $file->name, 'mode' => $mode]]);
|
||||||
->chmodFiles($this->path, [['file' => $file->name, 'mode' => $mode]]);
|
|
||||||
|
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Permissions changed to ' . $mode)
|
->title('Permissions changed to ' . $mode)
|
||||||
@ -273,11 +287,11 @@ class ListFiles extends ListRecords
|
|||||||
}),
|
}),
|
||||||
Action::make('archive')
|
Action::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)
|
||||||
->label('Archive')
|
->label('Archive')
|
||||||
->icon('tabler-archive')
|
->icon('tabler-archive')
|
||||||
->action(function (File $file) {
|
->action(function (File $file) {
|
||||||
$this->getDaemonFileRepository()
|
$this->getDaemonFileRepository()->compressFiles($this->path, [$file->name]);
|
||||||
->compressFiles($this->path, [$file->name]);
|
|
||||||
|
|
||||||
Activity::event('server:file.compress')
|
Activity::event('server:file.compress')
|
||||||
->property('directory', $this->path)
|
->property('directory', $this->path)
|
||||||
@ -293,12 +307,12 @@ class ListFiles extends ListRecords
|
|||||||
}),
|
}),
|
||||||
Action::make('unarchive')
|
Action::make('unarchive')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_ARCHIVE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_ARCHIVE, $server))
|
||||||
|
->disabled($this->isDisabled)
|
||||||
->label('Unarchive')
|
->label('Unarchive')
|
||||||
->icon('tabler-archive')
|
->icon('tabler-archive')
|
||||||
->visible(fn (File $file) => $file->isArchive())
|
->visible(fn (File $file) => $file->isArchive())
|
||||||
->action(function (File $file) {
|
->action(function (File $file) {
|
||||||
$this->getDaemonFileRepository()
|
$this->getDaemonFileRepository()->decompressFile($this->path, $file->name);
|
||||||
->decompressFile($this->path, $file->name);
|
|
||||||
|
|
||||||
Activity::event('server:file.decompress')
|
Activity::event('server:file.decompress')
|
||||||
->property('directory', $this->path)
|
->property('directory', $this->path)
|
||||||
@ -315,14 +329,14 @@ class ListFiles extends ListRecords
|
|||||||
]),
|
]),
|
||||||
DeleteAction::make()
|
DeleteAction::make()
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_DELETE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_DELETE, $server))
|
||||||
|
->disabled($this->isDisabled)
|
||||||
->label('')
|
->label('')
|
||||||
->icon('tabler-trash')
|
->icon('tabler-trash')
|
||||||
->requiresConfirmation()
|
->requiresConfirmation()
|
||||||
->modalDescription(fn (File $file) => $file->name)
|
->modalDescription(fn (File $file) => $file->name)
|
||||||
->modalHeading('Delete file?')
|
->modalHeading('Delete file?')
|
||||||
->action(function (File $file) {
|
->action(function (File $file) {
|
||||||
$this->getDaemonFileRepository()
|
$this->getDaemonFileRepository()->deleteFiles($this->path, [$file->name]);
|
||||||
->deleteFiles($this->path, [$file->name]);
|
|
||||||
|
|
||||||
Activity::event('server:file.delete')
|
Activity::event('server:file.delete')
|
||||||
->property('directory', $this->path)
|
->property('directory', $this->path)
|
||||||
@ -334,6 +348,7 @@ class ListFiles extends ListRecords
|
|||||||
BulkActionGroup::make([
|
BulkActionGroup::make([
|
||||||
BulkAction::make('move')
|
BulkAction::make('move')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_UPDATE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_UPDATE, $server))
|
||||||
|
->disabled($this->isDisabled)
|
||||||
->form([
|
->form([
|
||||||
TextInput::make('location')
|
TextInput::make('location')
|
||||||
->label('Directory')
|
->label('Directory')
|
||||||
@ -362,11 +377,11 @@ 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)
|
||||||
->action(function (Collection $files) {
|
->action(function (Collection $files) {
|
||||||
$files = $files->map(fn ($file) => $file['name'])->toArray();
|
$files = $files->map(fn ($file) => $file['name'])->toArray();
|
||||||
|
|
||||||
$this->getDaemonFileRepository()
|
$this->getDaemonFileRepository()->compressFiles($this->path, $files);
|
||||||
->compressFiles($this->path, $files);
|
|
||||||
|
|
||||||
Activity::event('server:file.compress')
|
Activity::event('server:file.compress')
|
||||||
->property('directory', $this->path)
|
->property('directory', $this->path)
|
||||||
@ -382,10 +397,10 @@ class ListFiles extends ListRecords
|
|||||||
}),
|
}),
|
||||||
DeleteBulkAction::make()
|
DeleteBulkAction::make()
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_DELETE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_DELETE, $server))
|
||||||
|
->disabled($this->isDisabled)
|
||||||
->action(function (Collection $files) {
|
->action(function (Collection $files) {
|
||||||
$files = $files->map(fn ($file) => $file['name'])->toArray();
|
$files = $files->map(fn ($file) => $file['name'])->toArray();
|
||||||
$this->getDaemonFileRepository()
|
$this->getDaemonFileRepository()->deleteFiles($this->path, $files);
|
||||||
->deleteFiles($this->path, $files);
|
|
||||||
|
|
||||||
Activity::event('server:file.delete')
|
Activity::event('server:file.delete')
|
||||||
->property('directory', $this->path)
|
->property('directory', $this->path)
|
||||||
@ -409,13 +424,13 @@ class ListFiles extends ListRecords
|
|||||||
return [
|
return [
|
||||||
HeaderAction::make('new_file')
|
HeaderAction::make('new_file')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_CREATE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_CREATE, $server))
|
||||||
|
->disabled($this->isDisabled)
|
||||||
->label('New File')
|
->label('New File')
|
||||||
->color('gray')
|
->color('gray')
|
||||||
->keyBindings('')
|
->keyBindings('')
|
||||||
->modalSubmitActionLabel('Create')
|
->modalSubmitActionLabel('Create')
|
||||||
->action(function ($data) {
|
->action(function ($data) {
|
||||||
$this->getDaemonFileRepository()
|
$this->getDaemonFileRepository()->putContent(join_paths($this->path, $data['name']), $data['editor'] ?? '');
|
||||||
->putContent(join_paths($this->path, $data['name']), $data['editor'] ?? '');
|
|
||||||
|
|
||||||
Activity::event('server:file.write')
|
Activity::event('server:file.write')
|
||||||
->property('file', join_paths($this->path, $data['name']))
|
->property('file', join_paths($this->path, $data['name']))
|
||||||
@ -439,11 +454,11 @@ class ListFiles extends ListRecords
|
|||||||
]),
|
]),
|
||||||
HeaderAction::make('new_folder')
|
HeaderAction::make('new_folder')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_CREATE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_CREATE, $server))
|
||||||
|
->disabled($this->isDisabled)
|
||||||
->label('New Folder')
|
->label('New Folder')
|
||||||
->color('gray')
|
->color('gray')
|
||||||
->action(function ($data) {
|
->action(function ($data) {
|
||||||
$this->getDaemonFileRepository()
|
$this->getDaemonFileRepository()->createDirectory($data['name'], $this->path);
|
||||||
->createDirectory($data['name'], $this->path);
|
|
||||||
|
|
||||||
Activity::event('server:file.create-directory')
|
Activity::event('server:file.create-directory')
|
||||||
->property(['directory' => $this->path, 'name' => $data['name']])
|
->property(['directory' => $this->path, 'name' => $data['name']])
|
||||||
@ -456,13 +471,13 @@ class ListFiles extends ListRecords
|
|||||||
]),
|
]),
|
||||||
HeaderAction::make('upload')
|
HeaderAction::make('upload')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_CREATE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_CREATE, $server))
|
||||||
|
->disabled($this->isDisabled)
|
||||||
->label('Upload')
|
->label('Upload')
|
||||||
->action(function ($data) {
|
->action(function ($data) {
|
||||||
if (count($data['files']) > 0 && !isset($data['url'])) {
|
if (count($data['files']) > 0 && !isset($data['url'])) {
|
||||||
/** @var UploadedFile $file */
|
/** @var UploadedFile $file */
|
||||||
foreach ($data['files'] as $file) {
|
foreach ($data['files'] as $file) {
|
||||||
$this->getDaemonFileRepository()
|
$this->getDaemonFileRepository()->putContent(join_paths($this->path, $file->getClientOriginalName()), $file->getContent());
|
||||||
->putContent(join_paths($this->path, $file->getClientOriginalName()), $file->getContent());
|
|
||||||
|
|
||||||
Activity::event('server:file.uploaded')
|
Activity::event('server:file.uploaded')
|
||||||
->property('directory', $this->path)
|
->property('directory', $this->path)
|
||||||
@ -470,8 +485,7 @@ class ListFiles extends ListRecords
|
|||||||
->log();
|
->log();
|
||||||
}
|
}
|
||||||
} elseif ($data['url'] !== null) {
|
} elseif ($data['url'] !== null) {
|
||||||
$this->getDaemonFileRepository()
|
$this->getDaemonFileRepository()->pull($data['url'], $this->path);
|
||||||
->pull($data['url'], $this->path);
|
|
||||||
|
|
||||||
Activity::event('server:file.pull')
|
Activity::event('server:file.pull')
|
||||||
->property('url', $data['url'])
|
->property('url', $data['url'])
|
||||||
@ -507,6 +521,7 @@ class ListFiles extends ListRecords
|
|||||||
]),
|
]),
|
||||||
HeaderAction::make('search')
|
HeaderAction::make('search')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_READ, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_READ, $server))
|
||||||
|
->disabled($this->isDisabled)
|
||||||
->label('Global Search')
|
->label('Global Search')
|
||||||
->modalSubmitActionLabel('Search')
|
->modalSubmitActionLabel('Search')
|
||||||
->form([
|
->form([
|
||||||
@ -522,17 +537,6 @@ class ListFiles extends ListRecords
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function route(string $path): PageRegistration
|
|
||||||
{
|
|
||||||
return new PageRegistration(
|
|
||||||
page: static::class,
|
|
||||||
route: fn (Panel $panel): Route => RouteFacade::get($path, static::class)
|
|
||||||
->middleware(static::getRouteMiddleware($panel))
|
|
||||||
->withoutMiddleware(static::getWithoutRouteMiddleware($panel))
|
|
||||||
->where('path', '.*'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
@ -558,4 +562,23 @@ class ListFiles extends ListRecords
|
|||||||
|
|
||||||
return $this->fileRepository;
|
return $this->fileRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getFailureNotification(): AlertBanner
|
||||||
|
{
|
||||||
|
return AlertBanner::make()
|
||||||
|
->title('Could not connect to the node!')
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function route(string $path): PageRegistration
|
||||||
|
{
|
||||||
|
return new PageRegistration(
|
||||||
|
page: static::class,
|
||||||
|
route: fn (Panel $panel): Route => RouteFacade::get($path, static::class)
|
||||||
|
->middleware(static::getRouteMiddleware($panel))
|
||||||
|
->withoutMiddleware(static::getWithoutRouteMiddleware($panel))
|
||||||
|
->where('path', '.*'),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ use Carbon\Carbon;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Http\Client\ConnectionException;
|
||||||
use Sushi\Sushi;
|
use Sushi\Sushi;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -150,10 +151,16 @@ class File extends Model
|
|||||||
try {
|
try {
|
||||||
$fileRepository = (new DaemonFileRepository())->setServer(self::$server);
|
$fileRepository = (new DaemonFileRepository())->setServer(self::$server);
|
||||||
|
|
||||||
if (!is_null(self::$searchTerm)) {
|
$contents = [];
|
||||||
$contents = cache()->remember('file_search_' . self::$path . '_' . self::$searchTerm, now()->addMinute(), fn () => $fileRepository->search(self::$searchTerm, self::$path));
|
|
||||||
} else {
|
try {
|
||||||
$contents = $fileRepository->getDirectory(self::$path ?? '/');
|
if (!is_null(self::$searchTerm)) {
|
||||||
|
$contents = cache()->remember('file_search_' . self::$path . '_' . self::$searchTerm, now()->addMinute(), fn () => $fileRepository->search(self::$searchTerm, self::$path));
|
||||||
|
} else {
|
||||||
|
$contents = $fileRepository->getDirectory(self::$path ?? '/');
|
||||||
|
}
|
||||||
|
} catch (ConnectionException $exception) {
|
||||||
|
report($exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($contents['error'])) {
|
if (isset($contents['error'])) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user