Documentation
¶
Overview ¶
Package attachment handles temporary attachment storage and secure token-based retrieval.
Index ¶
- Constants
- Variables
- type DBAttachment
- type Handler
- type Repository
- func (r *Repository) Create(ctx context.Context, topicID, mimeType string, fileSizeBytes int, ...) (*DBAttachment, error)
- func (r *Repository) DeleteExpired(ctx context.Context) error
- func (r *Repository) GetByToken(ctx context.Context, token string) (*DBAttachment, error)
- func (r *Repository) ListExpired(ctx context.Context) ([]DBAttachment, error)
- type Service
Constants ¶
const ( // MaxAttachmentSize is the maximum allowed plaintext size for an attachment in bytes (1 MB). MaxAttachmentSize = 1024 * 1024 // AttachmentTTL is how long attachments are retained before expiry. // The 6-hour window matches BeeBuzz's real-time alerting model and limits token exposure. AttachmentTTL = 6 * time.Hour )
Variables ¶
var ErrAttachmentExpired = fmt.Errorf("attachment expired: %w", core.ErrNotFound)
Functions ¶
This section is empty.
Types ¶
type DBAttachment ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles attachment HTTP requests.
func NewHandler ¶
NewHandler creates a new attachment handler.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository provides data access for the attachment domain.
func NewRepository ¶
func NewRepository(db *sqlx.DB) *Repository
NewRepository creates a new attachment repository.
func (*Repository) Create ¶
func (r *Repository) Create(ctx context.Context, topicID, mimeType string, fileSizeBytes int, ttl time.Duration) (*DBAttachment, error)
Create creates a new attachment record.
func (*Repository) DeleteExpired ¶
func (r *Repository) DeleteExpired(ctx context.Context) error
DeleteExpired deletes all expired attachments.
func (*Repository) GetByToken ¶
func (r *Repository) GetByToken(ctx context.Context, token string) (*DBAttachment, error)
GetByToken retrieves an attachment by token. Returns nil, nil if not found.
func (*Repository) ListExpired ¶
func (r *Repository) ListExpired(ctx context.Context) ([]DBAttachment, error)
ListExpired returns all attachment records where expires_at is in the past.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides attachment business logic.
func NewService ¶
func NewService(repo *Repository, attachmentsDir string, log *slog.Logger) *Service
NewService creates a new attachment service.
func (*Service) CleanupExpired ¶
CleanupExpired removes expired attachment files from disk and their DB records.
func (*Service) GetByToken ¶
GetByToken retrieves the raw (ciphertext) bytes and metadata for an attachment token. Returns core.ErrNotFound if the token does not exist, ErrAttachmentExpired if expired.
func (*Service) Store ¶
func (s *Service) Store(ctx context.Context, topicID, mimeType string, originalSize int, data []byte) (string, error)
Store persists already-encrypted ciphertext for a topic attachment and returns the access token. originalSize is the plaintext byte count, stored for UI display.