feat: simplify data and add cache to LocalFsAdapter

This commit is contained in:
Max Richter
2025-10-05 22:20:43 +02:00
parent fa283d5dd7
commit 6d92c92797
8 changed files with 196 additions and 160 deletions

View File

@@ -3,33 +3,26 @@ package adapters
import "time"
// Entry represents a file or directory in the filesystem.
type Entry struct {
Type string `json:"type"` // "file" | "dir"
Name string `json:"name"` // base name
Path string `json:"path"` // full path or virtual path
ModTime time.Time `json:"modTime"` // last modified
// File-only (optional)
MIME string `json:"mime,omitempty"` // e.g. "text/markdown"
Size int64 `json:"size,omitempty"` // bytes
// Content:
// - markdown file: any (parsed AST / arbitrary JSON)
// - directory: []*Entry (children)
// - other files: omitted
Content any `json:"content,omitempty"`
}
// FileAdapter is the interface for accessing the file system.
type FileAdapter interface {
Read(path string) (FsResponse, error)
Read(path string) (*Entry, error)
Write(path string, content []byte) error
}
type FsFile struct {
Name string `json:"name"`
Type string `json:"type"`
Content []byte `json:"content"`
ModTime time.Time `json:"modTime"`
}
type FsDirEntry struct {
Name string `json:"name"`
Type string `json:"type"`
IsDir bool `json:"isDir,omitempty"`
ModTime time.Time `json:"modTime"`
Content any `json:"content,omitempty"`
}
type FsDir struct {
Files []FsDirEntry `json:"files"`
Name string `json:"name"`
ModTime time.Time `json:"modTime"`
}
type FsResponse struct {
Dir *FsDir `json:"dir,omitempty"`
File *FsFile `json:"file,omitempty"`
}
}