mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-19 00:15:05 +00:00
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
This commit is contained in:
1 parent
b9a1808a24
commit
8053acfe8c
2 files changed
+16
-14
No files matched your search
+14
-12
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user