diff --git a/app/Filament/Server/Resources/FileResource/Pages/ListFiles.php b/app/Filament/Server/Resources/FileResource/Pages/ListFiles.php index e118d1bb2..0a284ed92 100644 --- a/app/Filament/Server/Resources/FileResource/Pages/ListFiles.php +++ b/app/Filament/Server/Resources/FileResource/Pages/ListFiles.php @@ -193,10 +193,10 @@ class ListFiles extends ListRecords ->required() ->live(), Placeholder::make('new_location') - ->content(fn (Get $get, File $file) => resolve_path('./' . join_paths($this->path, $get('location') ?? '/', $file->name))), + ->content(fn (Get $get, File $file) => resolve_path(join_paths($this->path, $get('location') ?? '/', $file->name))), ]) ->action(function ($data, File $file) { - $location = rtrim($data['location'], '/'); + $location = $data['location']; $files = [['to' => join_paths($location, $file->name), 'from' => $file->name]]; $this->getDaemonFileRepository()->renameFiles($this->path, $files); @@ -353,10 +353,10 @@ class ListFiles extends ListRecords ->required() ->live(), Placeholder::make('new_location') - ->content(fn (Get $get) => resolve_path('./' . join_paths($this->path, $get('location') ?? ''))), + ->content(fn (Get $get) => resolve_path(join_paths($this->path, $get('location') ?? ''))), ]) ->action(function (Collection $files, $data) { - $location = rtrim($data['location'], '/'); + $location = $data['location']; $files = $files->map(fn ($file) => ['to' => join_paths($location, $file['name']), 'from' => $file['name']])->toArray(); $this->getDaemonFileRepository()->renameFiles($this->path, $files); @@ -432,11 +432,12 @@ class ListFiles extends ListRecords ->modalSubmitActionLabel(trans('server/file.actions.new_file.create')) ->action(function ($data) { $path = join_paths($this->path, $data['name']); + try { $this->getDaemonFileRepository()->putContent($path, $data['editor'] ?? ''); Activity::event('server:file.write') - ->property('file', join_paths($path, $data['name'])) + ->property('file', $path) ->log(); } catch (FileExistsException) { AlertBanner::make('file_already_exists') diff --git a/app/helpers.php b/app/helpers.php index 88e309f78..e447e1fd6 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -52,11 +52,16 @@ if (!function_exists('convert_bytes_to_readable')) { if (!function_exists('join_paths')) { function join_paths(string $base, string ...$paths): string { - if ($base === '/') { - return str_replace('//', '', implode('/', $paths)); + $base = trim($base, '/'); + + $paths = array_map(fn (string $path) => trim($path, '/'), $paths); + $paths = array_filter($paths, fn (string $path) => strlen($path) > 0); + + if (empty($base)) { + return implode('/', $paths); } - return str_replace('//', '', $base . '/' . implode('/', $paths)); + return $base . '/' . implode('/', $paths); } }