Fix path resolving when moving files (#1116)

* don't resolve new path when moving file

* use full path in activity log

* don't require file name when moving
This commit is contained in:
Boy132 2025-03-18 17:36:27 +01:00 committed by GitHub
parent 4a7951995e
commit a05e330b19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 11 deletions

View File

@ -184,31 +184,33 @@ class ListFiles extends ListRecords
->icon('tabler-replace') ->icon('tabler-replace')
->form([ ->form([
TextInput::make('location') TextInput::make('location')
->label('File name') ->label('New location')
->hint('Enter the new name and directory of this file or folder, relative to the current directory.') ->hint('Enter the location of this file or folder, relative to the current directory.')
->default(fn (File $file) => $file->name)
->required() ->required()
->live(), ->live(),
Placeholder::make('new_location') Placeholder::make('new_location')
->content(fn (Get $get) => resolve_path('./' . join_paths($this->path, $get('location')))), ->content(fn (Get $get, File $file) => resolve_path('./' . join_paths($this->path, $get('location') ?? '/', $file->name))),
]) ])
->action(function ($data, File $file) { ->action(function ($data, File $file) {
$location = resolve_path(join_paths($this->path, $data['location'])); $location = rtrim($data['location'], '/');
$files = [['to' => join_paths($location, $file->name), 'from' => $file->name]];
$files = [['to' => $location, 'from' => $file->name]];
$this->getDaemonFileRepository() $this->getDaemonFileRepository()
->renameFiles($this->path, $files); ->renameFiles($this->path, $files);
$oldLocation = join_paths($this->path, $file->name);
$newLocation = resolve_path(join_paths($this->path, $location, $file->name));
Activity::event('server:file.rename') Activity::event('server:file.rename')
->property('directory', $this->path) ->property('directory', $this->path)
->property('files', $files) ->property('files', $files)
->property('to', $location) ->property('to', $newLocation)
->property('from', $file->name) ->property('from', $oldLocation)
->log(); ->log();
Notification::make() Notification::make()
->title(join_paths($this->path, $file->name) . ' was moved to ' . $location) ->title('File Moved')
->body($oldLocation . ' -> ' . $newLocation)
->success() ->success()
->send(); ->send();
}), }),

View File

@ -74,7 +74,7 @@ return [
'delete' => 'Deleted <b>:directory:files</b>|Deleted <b>:count</b> files in <b>:directory</b>', 'delete' => 'Deleted <b>:directory:files</b>|Deleted <b>:count</b> files in <b>:directory</b>',
'download' => 'Downloaded <b>:file</b>', 'download' => 'Downloaded <b>:file</b>',
'pull' => 'Downloaded a remote file from <b>:url</b> to <b>:directory</b>', 'pull' => 'Downloaded a remote file from <b>:url</b> to <b>:directory</b>',
'rename' => 'Renamed <b>:directory:from</b> to <b>:directory:to</b>|Renamed <b>:count</b> files in <b>:directory</b>', 'rename' => 'Moved/ Renamed <b>:from</b> to <b>:to</b>|Moved/ Renamed <b>:count</b> files in <b>:directory</b>',
'write' => 'Wrote new content to <b>:file</b>', 'write' => 'Wrote new content to <b>:file</b>',
'upload' => 'Began a file upload', 'upload' => 'Began a file upload',
'uploaded' => 'Uploaded <b>:directory:file</b>', 'uploaded' => 'Uploaded <b>:directory:file</b>',