Add file attachment support with SHA-256 content-addressable storage, automatic deduplication, MIME detection, and garbage collection for orphaned files. Includes MCP tools (upload_attachment, download_attachment, gc_attachments), REST API endpoints for Web UI, and comprehensive tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
26 lines
1009 B
Go
26 lines
1009 B
Go
package attachments
|
|
|
|
import "context"
|
|
|
|
// Store is the metadata persistence interface for attachments.
|
|
type Store interface {
|
|
// InsertMetadata inserts a new attachment metadata row.
|
|
InsertMetadata(ctx context.Context, a *Attachment) error
|
|
|
|
// GetByHash returns all attachment metadata rows matching the given hash.
|
|
GetByHash(ctx context.Context, hash string) ([]*Attachment, error)
|
|
|
|
// GetByMessageID returns all attachment metadata rows for a given message.
|
|
GetByMessageID(ctx context.Context, messageID int64) ([]*Attachment, error)
|
|
|
|
// DeleteByHash removes all metadata rows matching the given hash.
|
|
DeleteByHash(ctx context.Context, hash string) error
|
|
|
|
// FindOrphanHashes returns hashes that have no message_id reference
|
|
// (message_id IS NULL or the referenced message no longer exists).
|
|
FindOrphanHashes(ctx context.Context) ([]string, error)
|
|
|
|
// CountReferences returns the number of metadata rows referencing the hash.
|
|
CountReferences(ctx context.Context, hash string) (int64, error)
|
|
}
|