mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
add rename method
This commit is contained in:
parent
381cac79b2
commit
47faf0b0e5
18
fileinfo.go
18
fileinfo.go
@ -79,3 +79,21 @@ func (fi FileInfo) Delete() (int, error) {
|
|||||||
|
|
||||||
return http.StatusOK, nil
|
return http.StatusOK, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rename function is used tor rename a file or a directory
|
||||||
|
func (fi FileInfo) Rename(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
|
newname := r.Header.Get("Rename-To")
|
||||||
|
if newname == "" {
|
||||||
|
return http.StatusBadRequest, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
newpath := filepath.Clean(newname)
|
||||||
|
newpath = strings.Replace(fi.Path, fi.Name, newname, 1)
|
||||||
|
|
||||||
|
if err := os.Rename(fi.Path, newpath); err != nil {
|
||||||
|
return ErrorToHTTPCode(err), err
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Redirect(w, r, strings.Replace(fi.URL, fi.Name, newname, 1), http.StatusTemporaryRedirect)
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
@ -79,8 +79,7 @@ func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, err
|
|||||||
return http.StatusOK, nil
|
return http.StatusOK, nil
|
||||||
case http.MethodPatch:
|
case http.MethodPatch:
|
||||||
// Rename a file or directory
|
// Rename a file or directory
|
||||||
|
return fi.Rename(w, r)
|
||||||
return http.StatusOK, nil
|
|
||||||
default:
|
default:
|
||||||
return http.StatusNotImplemented, nil
|
return http.StatusNotImplemented, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user