feat: simplify data and add cache to LocalFsAdapter
This commit is contained in:
@@ -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"`
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user