fix: match CHFS file API response types

This commit is contained in:
OpenClaw Agent
2026-09-21 19:26:40 +08:00
parent a6637f8f7e
commit b372cf090d
+7 -5
View File
@@ -45,7 +45,6 @@ type Server struct {
} }
type fileInfo struct { type fileInfo struct {
Name string `json:"name"` Name string `json:"name"`
Path string `json:"path"`
Size int64 `json:"size"` Size int64 `json:"size"`
Modified string `json:"modified"` Modified string `json:"modified"`
Dir bool `json:"dir"` Dir bool `json:"dir"`
@@ -170,7 +169,7 @@ func (s *Server) files(w http.ResponseWriter, r *http.Request) {
if !m.HasRead() { if !m.HasRead() {
// CHFS keeps the files endpoint HTTP-successful for a denied directory // CHFS keeps the files endpoint HTTP-successful for a denied directory
// and returns an empty listing with currentMask="". // and returns an empty listing with currentMask="".
writeJSON(w, map[string]any{"files": []fileInfo{}, "currentMask": "", "virtualRoot": false}) writeJSON(w, map[string]any{"files": []fileInfo{}, "currentMask": "", "virtualRoot": 0})
return return
} }
list, e := s.Store.List(p) list, e := s.Store.List(p)
@@ -197,9 +196,12 @@ func (s *Server) files(w http.ResponseWriter, r *http.Request) {
} }
} }
} }
out = append(out, fileInfo{Name: fi.Name(), Path: fp, Size: fi.Size(), Modified: originalTime(fi.ModTime()), Dir: fi.IsDir(), Mask: permString(a.MaskForEntry(fp)), GuestMask: permString(s.Auth.Guest.MaskForEntry(fp)), HasSubDir: sub, Icon: iconFor(fi)}) out = append(out, fileInfo{Name: fi.Name(), Size: fi.Size(), Modified: originalTime(fi.ModTime()), Dir: fi.IsDir(), Mask: permString(a.MaskForEntry(fp)), GuestMask: permString(s.Auth.Guest.MaskForEntry(fp)), HasSubDir: sub, Icon: iconFor(fi)})
}
virtual := 0
if p == "" && s.MultiRoot {
virtual = 1
} }
virtual := p == "" && s.MultiRoot
writeJSON(w, map[string]any{"files": out, "currentMask": permString(m), "virtualRoot": virtual}) writeJSON(w, map[string]any{"files": out, "currentMask": permString(m), "virtualRoot": virtual})
} }
func (s *Server) newdir(w http.ResponseWriter, r *http.Request) { func (s *Server) newdir(w http.ResponseWriter, r *http.Request) {
@@ -490,7 +492,7 @@ func (s *Server) search(w http.ResponseWriter, r *http.Request) {
continue continue
} }
if needle == "" || strings.Contains(strings.ToLower(fi.Name()), needle) { if needle == "" || strings.Contains(strings.ToLower(fi.Name()), needle) {
out = append(out, fileInfo{Name: fi.Name(), Path: "/" + strings.Trim(p, "/"), Size: fi.Size(), Modified: originalTime(fi.ModTime()), Dir: fi.IsDir(), Mask: permString(a.MaskForEntry(p)), GuestMask: permString(s.Auth.Guest.MaskForEntry(p)), HasSubDir: false, Icon: iconFor(fi)}) out = append(out, fileInfo{Name: fi.Name(), Size: fi.Size(), Modified: originalTime(fi.ModTime()), Dir: fi.IsDir(), Mask: permString(a.MaskForEntry(p)), GuestMask: permString(s.Auth.Guest.MaskForEntry(p)), HasSubDir: false, Icon: iconFor(fi)})
} }
if fi.IsDir() { if fi.IsDir() {
if err := walk(p); err != nil { if err := walk(p); err != nil {