fix: align api fields with CHFS frontend

This commit is contained in:
OpenClaw Agent
2026-09-21 13:03:42 +08:00
parent 79070af15d
commit cc09fc8fc2
+14 -5
View File
@@ -134,9 +134,9 @@ func (s *Server) rename(w http.ResponseWriter, r *http.Request) {
func (s *Server) remove(w http.ResponseWriter, r *http.Request) {
a := account(r, s)
_ = r.ParseForm()
items := r.Form["path"]
items := r.Form["filepath"]
if len(items) == 0 {
items = r.Form["paths"]
items = r.Form["path"]
}
for _, p := range items {
if !a.MaskFor(p).HasDelete() {
@@ -151,11 +151,16 @@ func (s *Server) remove(w http.ResponseWriter, r *http.Request) {
writeJSON(w, map[string]any{"ok": true})
}
func (s *Server) exist(w http.ResponseWriter, r *http.Request) {
p := qpath(r)
p := strings.Trim(strings.ReplaceAll(r.URL.Query().Get("file"), "\\", "/"), "/")
_, e := s.Store.Stat(p)
writeJSON(w, map[string]any{"exist": e == nil})
}
func (s *Server) session(w http.ResponseWriter, r *http.Request) {
if r.Method == "DELETE" {
http.SetCookie(w, &http.Cookie{Name: "chfs_token", Value: "", Path: "/", MaxAge: -1, HttpOnly: true})
writeJSON(w, map[string]any{"ok": true})
return
}
if r.Method == "GET" {
a := account(r, s)
writeJSON(w, map[string]any{"login": a != nil, "user": a.Username})
@@ -174,7 +179,10 @@ func (s *Server) session(w http.ResponseWriter, r *http.Request) {
}
func (s *Server) newtext(w http.ResponseWriter, r *http.Request) {
a := account(r, s)
p := strings.Trim(r.FormValue("path"), "/")
p := strings.Trim(r.FormValue("filepath"), "/")
if filename := strings.Trim(r.FormValue("filename"), "/"); filename != "" {
p = path.Join(p, filename)
}
if !a.MaskFor(p).HasWrite() {
http.Error(w, "forbidden", 403)
return
@@ -191,7 +199,7 @@ func (s *Server) newtext(w http.ResponseWriter, r *http.Request) {
func (s *Server) updatetext(w http.ResponseWriter, r *http.Request) { s.newtext(w, r) }
func (s *Server) upload(w http.ResponseWriter, r *http.Request) {
a := account(r, s)
dir := strings.Trim(r.FormValue("path"), "/")
dir := strings.Trim(r.FormValue("folder"), "/")
if !a.MaskFor(dir).HasWrite() {
http.Error(w, "forbidden", 403)
return
@@ -210,6 +218,7 @@ func (s *Server) upload(w http.ResponseWriter, r *http.Request) {
saved = append(saved, h.Filename)
}
}
w.WriteHeader(http.StatusCreated)
writeJSON(w, map[string]any{"ok": true, "files": saved})
}
func savePart(st storage.Storage, dir string, h *multipart.FileHeader) error {