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')
->form([
TextInput::make('location')
->label('File name')
->hint('Enter the new name and directory of this file or folder, relative to the current directory.')
->default(fn (File $file) => $file->name)
->label('New location')
->hint('Enter the location of this file or folder, relative to the current directory.')
->required()
->live(),
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) {
$location = resolve_path(join_paths($this->path, $data['location']));
$files = [['to' => $location, 'from' => $file->name]];
$location = rtrim($data['location'], '/');
$files = [['to' => join_paths($location, $file->name), 'from' => $file->name]];
$this->getDaemonFileRepository()
->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')
->property('directory', $this->path)
->property('files', $files)
->property('to', $location)
->property('from', $file->name)
->property('to', $newLocation)
->property('from', $oldLocation)
->log();
Notification::make()
->title(join_paths($this->path, $file->name) . ' was moved to ' . $location)
->title('File Moved')
->body($oldLocation . ' -> ' . $newLocation)
->success()
->send();
}),

View File

@ -74,7 +74,7 @@ return [
'delete' => 'Deleted <b>:directory:files</b>|Deleted <b>:count</b> files in <b>:directory</b>',
'download' => 'Downloaded <b>:file</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>',
'upload' => 'Began a file upload',
'uploaded' => 'Uploaded <b>:directory:file</b>',