From 4d0aabe91e979e29297af315a1ae878c6e8845bb Mon Sep 17 00:00:00 2001 From: Boy132 Date: Thu, 26 Jun 2025 17:00:37 +0200 Subject: [PATCH 1/2] Schedule task improvements (#1468) --- .../RelationManagers/TasksRelationManager.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Filament/Server/Resources/ScheduleResource/RelationManagers/TasksRelationManager.php b/app/Filament/Server/Resources/ScheduleResource/RelationManagers/TasksRelationManager.php index 5b7b2ffe4..141818a54 100644 --- a/app/Filament/Server/Resources/ScheduleResource/RelationManagers/TasksRelationManager.php +++ b/app/Filament/Server/Resources/ScheduleResource/RelationManagers/TasksRelationManager.php @@ -6,6 +6,7 @@ use App\Facades\Activity; use App\Models\Schedule; use App\Models\Task; use Filament\Forms\Components\Field; +use Filament\Forms\Set; use Filament\Tables\Actions\DeleteAction; use Filament\Forms\Components\Select; use Filament\Forms\Components\Textarea; @@ -45,10 +46,11 @@ class TasksRelationManager extends RelationManager Select::make('action') ->required() ->live() - ->disableOptionWhen(fn (string $value): bool => $value === Task::ACTION_BACKUP && $schedule->server->backup_limit === 0) + ->disableOptionWhen(fn (string $value) => $value === Task::ACTION_BACKUP && $schedule->server->backup_limit === 0) ->options($this->getActionOptions()) ->selectablePlaceholder(false) - ->default(Task::ACTION_POWER), + ->default(Task::ACTION_POWER) + ->afterStateUpdated(fn ($state, Set $set) => $set('payload', $state === Task::ACTION_POWER ? 'restart' : null)), Textarea::make('payload') ->hidden(fn (Get $get) => $get('action') === Task::ACTION_POWER) ->label(fn (Get $get) => $this->getActionOptions(false)[$get('action')] ?? 'Payload'), @@ -81,7 +83,8 @@ class TasksRelationManager extends RelationManager $schedule = $this->getOwnerRecord(); return $table - ->reorderable('sequence_id', true) + ->reorderable('sequence_id') + ->defaultSort('sequence_id') ->columns([ TextColumn::make('action') ->state(fn (Task $task) => $this->getActionOptions()[$task->action] ?? $task->action), From cdcd1c521ee7fa5620ac8da043227debf9b1501b Mon Sep 17 00:00:00 2001 From: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> Date: Thu, 26 Jun 2025 21:04:33 +0200 Subject: [PATCH 2/2] Add `FileExistsException` & Fix error reporting (#1417) --- .../Repository/FileExistsException.php | 7 ++++ .../FileResource/Pages/ListFiles.php | 40 +++++++++++++++---- .../Daemon/DaemonFileRepository.php | 19 ++++++++- app/Repositories/Daemon/DaemonRepository.php | 3 ++ 4 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 app/Exceptions/Repository/FileExistsException.php diff --git a/app/Exceptions/Repository/FileExistsException.php b/app/Exceptions/Repository/FileExistsException.php new file mode 100644 index 000000000..b71649483 --- /dev/null +++ b/app/Exceptions/Repository/FileExistsException.php @@ -0,0 +1,7 @@ +keyBindings('') ->modalSubmitActionLabel('Create') ->action(function ($data) { - $this->getDaemonFileRepository()->putContent(join_paths($this->path, $data['name']), $data['editor'] ?? ''); + $path = join_paths($this->path, $data['name']); + try { + $this->getDaemonFileRepository()->putContent($path, $data['editor'] ?? ''); - Activity::event('server:file.write') - ->property('file', join_paths($this->path, $data['name'])) - ->log(); + Activity::event('server:file.write') + ->property('file', join_paths($path, $data['name'])) + ->log(); + } catch (FileExistsException) { + AlertBanner::make() + ->title('' . $path . ' already exists!') + ->danger() + ->closable() + ->send(); + + $this->redirect(self::getUrl(['path' => dirname($path)])); + } }) ->form([ TextInput::make('name') @@ -448,11 +461,22 @@ class ListFiles extends ListRecords ->label('New Folder') ->color('gray') ->action(function ($data) { - $this->getDaemonFileRepository()->createDirectory($data['name'], $this->path); + try { + $this->getDaemonFileRepository()->createDirectory($data['name'], $this->path); - Activity::event('server:file.create-directory') - ->property(['directory' => $this->path, 'name' => $data['name']]) - ->log(); + Activity::event('server:file.create-directory') + ->property(['directory' => $this->path, 'name' => $data['name']]) + ->log(); + } catch (FileExistsException) { + $path = join_paths($this->path, $data['name']); + AlertBanner::make() + ->title('' . $path . ' already exists!') + ->danger() + ->closable() + ->send(); + + $this->redirect(self::getUrl(['path' => dirname($path)])); + } }) ->form([ TextInput::make('name') diff --git a/app/Repositories/Daemon/DaemonFileRepository.php b/app/Repositories/Daemon/DaemonFileRepository.php index f7d5c78e3..b1385fe92 100644 --- a/app/Repositories/Daemon/DaemonFileRepository.php +++ b/app/Repositories/Daemon/DaemonFileRepository.php @@ -5,6 +5,7 @@ namespace App\Repositories\Daemon; use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Http\Client\Response; use App\Exceptions\Http\Server\FileSizeTooLargeException; +use App\Exceptions\Repository\FileExistsException; use App\Exceptions\Repository\FileNotEditableException; use Illuminate\Http\Client\ConnectionException; @@ -46,13 +47,20 @@ class DaemonFileRepository extends DaemonRepository * a file. * * @throws ConnectionException + * @throws FileExistsException */ public function putContent(string $path, string $content): Response { - return $this->getHttpClient() + $response = $this->getHttpClient() ->withQueryParameters(['file' => $path]) ->withBody($content) ->post("/api/servers/{$this->server->uuid}/files/write"); + + if ($response->getStatusCode() === 400) { + throw new FileExistsException(); + } + + return $response; } /** @@ -73,15 +81,22 @@ class DaemonFileRepository extends DaemonRepository * Creates a new directory for the server in the given $path. * * @throws ConnectionException + * @throws FileExistsException */ public function createDirectory(string $name, string $path): Response { - return $this->getHttpClient()->post("/api/servers/{$this->server->uuid}/files/create-directory", + $response = $this->getHttpClient()->post("/api/servers/{$this->server->uuid}/files/create-directory", [ 'name' => $name, 'path' => $path, ] ); + + if ($response->getStatusCode() === 400) { + throw new FileExistsException(); + } + + return $response; } /** diff --git a/app/Repositories/Daemon/DaemonRepository.php b/app/Repositories/Daemon/DaemonRepository.php index 6b3b553d6..6d58e7646 100644 --- a/app/Repositories/Daemon/DaemonRepository.php +++ b/app/Repositories/Daemon/DaemonRepository.php @@ -57,6 +57,9 @@ abstract class DaemonRepository if (is_bool($condition)) { return $condition; } + if ($condition->clientError()) { + return false; + } $header = $condition->header('User-Agent'); if (