feat(files): implement file storage functionality with save, load, and list operations

This commit is contained in:
2026-03-30 22:24:18 +02:00
parent 79d8219836
commit 7f2b2b9fee
12 changed files with 676 additions and 33 deletions

View File

@@ -35,6 +35,7 @@ func Fallback(capture config.CaptureConfig) thoughttypes.ThoughtMetadata {
Topics: []string{topicFallback},
Type: normalizeType(capture.MetadataDefaults.Type),
Source: normalizeSource(capture.Source),
Attachments: []thoughttypes.ThoughtAttachment{},
}
}
@@ -46,6 +47,7 @@ func Normalize(in thoughttypes.ThoughtMetadata, capture config.CaptureConfig) th
Topics: normalizeList(in.Topics, maxTopics),
Type: normalizeType(in.Type),
Source: normalizeSource(in.Source),
Attachments: normalizeAttachments(in.Attachments),
}
if len(out.Topics) == 0 {
@@ -127,10 +129,42 @@ func Merge(base, patch thoughttypes.ThoughtMetadata, capture config.CaptureConfi
if strings.TrimSpace(patch.Source) != "" {
merged.Source = patch.Source
}
if len(patch.Attachments) > 0 {
merged.Attachments = append(append([]thoughttypes.ThoughtAttachment{}, merged.Attachments...), patch.Attachments...)
}
return Normalize(merged, capture)
}
func normalizeAttachments(values []thoughttypes.ThoughtAttachment) []thoughttypes.ThoughtAttachment {
seen := make(map[string]struct{}, len(values))
result := make([]thoughttypes.ThoughtAttachment, 0, len(values))
for _, value := range values {
if value.FileID.String() == "" || value.FileID.String() == "00000000-0000-0000-0000-000000000000" {
continue
}
key := value.FileID.String()
if _, ok := seen[key]; ok {
continue
}
value.Name = strings.TrimSpace(value.Name)
value.MediaType = strings.TrimSpace(value.MediaType)
value.Kind = strings.TrimSpace(value.Kind)
if value.SizeBytes < 0 {
value.SizeBytes = 0
}
value.SHA256 = strings.TrimSpace(value.SHA256)
seen[key] = struct{}{}
result = append(result, value)
}
return result
}
func SortedTopCounts(in map[string]int, limit int) []thoughttypes.KeyCount {
out := make([]thoughttypes.KeyCount, 0, len(in))
for key, count := range in {