fix: restore search result paths

This commit is contained in:
OpenClaw Agent
2026-09-21 19:40:06 +08:00
parent d4a1a5af05
commit 2abc3747a6
+14 -2
View File
@@ -474,6 +474,18 @@ func (s *Server) upload2(w http.ResponseWriter, r *http.Request) {
writeCreated(w) writeCreated(w)
} }
type searchFileInfo struct {
Name string `json:"name"`
Path string `json:"path"`
Size int64 `json:"size"`
Modified string `json:"modified"`
Dir bool `json:"dir"`
Mask string `json:"mask"`
GuestMask string `json:"guestMask"`
HasSubDir bool `json:"hasSubDir"`
Icon string `json:"icon"`
}
func (s *Server) search(w http.ResponseWriter, r *http.Request) { func (s *Server) search(w http.ResponseWriter, r *http.Request) {
a := account(r, s) a := account(r, s)
rootMask := a.MaskFor("") rootMask := a.MaskFor("")
@@ -482,7 +494,7 @@ func (s *Server) search(w http.ResponseWriter, r *http.Request) {
return return
} }
needle := strings.ToLower(strings.TrimSpace(r.URL.Query().Get("str"))) needle := strings.ToLower(strings.TrimSpace(r.URL.Query().Get("str")))
out := make([]fileInfo, 0) out := make([]searchFileInfo, 0)
var walk func(string) error var walk func(string) error
walk = func(dir string) error { walk = func(dir string) error {
items, err := s.Store.List(dir) items, err := s.Store.List(dir)
@@ -495,7 +507,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(), 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, searchFileInfo{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)})
} }
if fi.IsDir() { if fi.IsDir() {
if err := walk(p); err != nil { if err := walk(p); err != nil {