From 8053acfe8c14bafc5e63326c00d28d16dcce3639 Mon Sep 17 00:00:00 2001 From: viettranx Date: Sun, 15 Mar 2026 17:26:09 +0700 Subject: [PATCH] fix(storage): fix subtree lazy-loading and preserve workspace media files - Fix storage file listing to skip subtree root when ?path= is used, preventing duplicate folder nesting in the file browser tree - Comment out os.Remove calls in persistMedia to keep original workspace files after persisting to media store --- internal/agent/media.go | 26 ++++++++++++++------------ internal/http/storage.go | 4 ++-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/internal/agent/media.go b/internal/agent/media.go index a687c68b..6223d66e 100644 --- a/internal/agent/media.go +++ b/internal/agent/media.go @@ -55,13 +55,14 @@ func loadImages(files []bus.MediaFile) []providers.ImageContent { // If mediaStore is nil, falls back to legacy behavior (no persistence, delete temp files). func (l *Loop) persistMedia(sessionKey string, files []bus.MediaFile) []providers.MediaRef { if l.mediaStore == nil { - // Fallback: no persistent storage configured — delete temp files after loading. - slog.Warn("media: no media store configured, temp files will be deleted", "agent", l.id) - defer func() { - for _, f := range files { - _ = os.Remove(f.Path) - } - }() + // Fallback: no persistent storage configured. + // slog.Warn("media: no media store configured, temp files will be deleted", "agent", l.id) + // Keep workspace files — don't delete originals. + // defer func() { + // for _, f := range files { + // _ = os.Remove(f.Path) + // } + // }() return nil } @@ -82,17 +83,18 @@ func (l *Loop) persistMedia(sessionKey string, files []bus.MediaFile) []provider } else { srcPath = sanitized mime = "image/jpeg" // sanitized output is always JPEG - // Clean up original if sanitized to a different file. - if sanitized != f.Path { - _ = os.Remove(f.Path) - } + // Keep workspace files — don't delete originals after sanitization. + // if sanitized != f.Path { + // _ = os.Remove(f.Path) + // } } } id, _, err := l.mediaStore.SaveFile(sessionKey, srcPath, mime) if err != nil { slog.Warn("media: failed to persist file", "path", f.Path, "error", err) - _ = os.Remove(srcPath) + // Keep workspace files — don't delete on persist failure. + // _ = os.Remove(srcPath) continue } diff --git a/internal/http/storage.go b/internal/http/storage.go index 3767f23f..f8b47620 100644 --- a/internal/http/storage.go +++ b/internal/http/storage.go @@ -126,10 +126,10 @@ func (h *StorageHandler) handleList(w http.ResponseWriter, r *http.Request) { if err != nil { return nil } - rel, _ := filepath.Rel(h.baseDir, path) - if rel == "." { + if path == rootDir { return nil } + rel, _ := filepath.Rel(h.baseDir, path) // Skip symlinks if d.Type()&os.ModeSymlink != 0 {