From cc09fc8fc2d1774f704686896641220eee11b446 Mon Sep 17 00:00:00 2001 From: OpenClaw Agent Date: Mon, 21 Sep 2026 13:03:42 +0800 Subject: [PATCH] fix: align api fields with CHFS frontend --- chfs-ng/internal/api/server.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/chfs-ng/internal/api/server.go b/chfs-ng/internal/api/server.go index 3ab97e8..4b384a3 100644 --- a/chfs-ng/internal/api/server.go +++ b/chfs-ng/internal/api/server.go @@ -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 {