FIX: Properly detect if target path is a folder when moving files
This commit is contained in:
@@ -1319,10 +1319,21 @@ func moveOrgFileHandler(w http.ResponseWriter, r *http.Request, db *database.DB,
|
||||
return
|
||||
}
|
||||
|
||||
// Determine new file name
|
||||
// Determine new file name - check if target is a folder
|
||||
var newPath string
|
||||
if strings.HasSuffix(req.TargetPath, "/") {
|
||||
// Moving into a folder
|
||||
var targetFile *database.File
|
||||
for i := range sourceFiles {
|
||||
if sourceFiles[i].Path == req.TargetPath {
|
||||
targetFile = &sourceFiles[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if targetFile != nil && targetFile.Type == "folder" {
|
||||
// Target is a folder, move file into it
|
||||
newPath = path.Join(req.TargetPath, sourceFile.Name)
|
||||
} else if targetFile == nil && strings.HasSuffix(req.TargetPath, "/") {
|
||||
// Target path doesn't exist but ends with /, treat as folder
|
||||
newPath = path.Join(req.TargetPath, sourceFile.Name)
|
||||
} else {
|
||||
// Moving/renaming to a specific path
|
||||
@@ -1514,10 +1525,21 @@ func moveUserFileHandler(w http.ResponseWriter, r *http.Request, db *database.DB
|
||||
return
|
||||
}
|
||||
|
||||
// Determine new file name
|
||||
// Determine new file name - check if target is a folder
|
||||
var newPath string
|
||||
if strings.HasSuffix(req.TargetPath, "/") {
|
||||
// Moving into a folder
|
||||
var targetFile *database.File
|
||||
for i := range sourceFiles {
|
||||
if sourceFiles[i].Path == req.TargetPath {
|
||||
targetFile = &sourceFiles[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if targetFile != nil && targetFile.Type == "folder" {
|
||||
// Target is a folder, move file into it
|
||||
newPath = path.Join(req.TargetPath, sourceFile.Name)
|
||||
} else if targetFile == nil && strings.HasSuffix(req.TargetPath, "/") {
|
||||
// Target path doesn't exist but ends with /, treat as folder
|
||||
newPath = path.Join(req.TargetPath, sourceFile.Name)
|
||||
} else {
|
||||
// Moving/renaming to a specific path
|
||||
|
||||
Reference in New Issue
Block a user