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)
}
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) {
a := account(r, s)
rootMask := a.MaskFor("")
@@ -482,7 +494,7 @@ func (s *Server) search(w http.ResponseWriter, r *http.Request) {
return
}
needle := strings.ToLower(strings.TrimSpace(r.URL.Query().Get("str")))
out := make([]fileInfo, 0)
out := make([]searchFileInfo, 0)
var walk func(string) error
walk = func(dir string) error {
items, err := s.Store.List(dir)
@@ -495,7 +507,7 @@ func (s *Server) search(w http.ResponseWriter, r *http.Request) {
continue
}
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 err := walk(p); err != nil {