feat: implement multi-root virtual filesystem

This commit is contained in:
OpenClaw Agent
2026-09-21 13:29:50 +08:00
parent 8a82e48507
commit 633c833d1c
3 changed files with 149 additions and 11 deletions
+7 -5
View File
@@ -24,6 +24,7 @@ type Server struct {
Sessions map[string]*auth.Account
WebDAVRoot string
Allow string
MultiRoot bool
}
type fileInfo struct {
Name string `json:"name"`
@@ -74,13 +75,13 @@ func qpath(r *http.Request) string {
}
func permString(p auth.PermMask) string {
if p.HasDelete() {
return "d"
return "RWD"
}
if p.HasWrite() {
return "w"
return "RW"
}
if p.HasRead() {
return "r"
return "R"
}
return ""
}
@@ -106,9 +107,10 @@ func (s *Server) files(w http.ResponseWriter, r *http.Request) {
sub = len(xs) > 0
}
}
out = append(out, fileInfo{Name: fi.Name(), Path: fp, Size: fi.Size(), Modified: fi.ModTime().Format(time.RFC3339), Dir: fi.IsDir(), Mask: permString(a.MaskFor(fp)), HasSubDir: sub})
out = append(out, fileInfo{Name: fi.Name(), Path: fp, Size: fi.Size(), Modified: fi.ModTime().Format(time.RFC3339), Dir: fi.IsDir(), Mask: permString(a.MaskFor(fp)), GuestMask: permString(s.Auth.Guest.MaskFor(fp)), HasSubDir: sub})
}
writeJSON(w, map[string]any{"files": out, "currentMask": permString(m), "virtualRoot": false})
virtual := p == "" && s.MultiRoot
writeJSON(w, map[string]any{"files": out, "currentMask": permString(m), "virtualRoot": virtual})
}
func (s *Server) newdir(w http.ResponseWriter, r *http.Request) {
_ = r.ParseMultipartForm(16 << 20)