Versions in this module Expand all Collapse all v0 v0.2.0 Oct 23, 2026 Changes in this version + const DefaultMaxConcurrentDecodes + const DefaultMaxDecodeMemory + const DefaultPageSize + const MaxPageSize + const MaxPropertiesSize + var ErrInvalid = errors.New("medialibrary: invalid input") + var ErrWriteWindowExceeded = fmt.Errorf("medialibrary: file writes exceeded the orphan grace window: %w", ErrConflict) + func ContentDisposition(disposition, fileName string) string + func InlineSafe(mimeType string) bool type Config + MaxConcurrentDecodes int + MaxDecodeMemory int64 + OrphanGrace time.Duration + type Cursor struct + Collection string + ID uuid.UUID + Order int + type ListOptions struct + After *Cursor + Collection string + Limit int type Ref + func (r Ref) IsZero() bool v0.1.0 Oct 23, 2026 Changes in this version + const DefaultMaxPixels + const DefaultMaxSize + const DefaultOrphanGrace + var ErrCollectionFull = errors.New("medialibrary: collection is full") + var ErrConflict = errors.New("medialibrary: media already exists") + var ErrConversionNotReady = errors.New("medialibrary: conversion not ready") + var ErrEmptyFile = errors.New("medialibrary: empty file") + var ErrEnqueue = errors.New("medialibrary: enqueue conversions") + var ErrFileNotFound = errors.New("medialibrary: file not found") + var ErrFileTooLarge = errors.New("medialibrary: file too large") + var ErrImageTooLarge = errors.New("medialibrary: image exceeds pixel limit") + var ErrInvalidConfig = errors.New("medialibrary: invalid config") + var ErrInvalidFileName = errors.New("medialibrary: invalid file name") + var ErrInvalidMedia = errors.New("medialibrary: invalid media") + var ErrInvalidOrder = errors.New("medialibrary: invalid order") + var ErrInvalidOwner = errors.New("medialibrary: invalid owner") + var ErrInvalidPath = errors.New("medialibrary: invalid path") + var ErrMimeTypeNotAllowed = errors.New("medialibrary: mime type not allowed") + var ErrNoPublicURL = errors.New("medialibrary: disk has no public url") + var ErrNotFound = errors.New("medialibrary: media not found") + var ErrSignedURLUnsupported = errors.New("medialibrary: disk does not support signed urls") + var ErrSizeMismatch = errors.New("medialibrary: size mismatch") + var ErrUnknownCollection = errors.New("medialibrary: unknown collection") + var ErrUnknownConversion = errors.New("medialibrary: unknown conversion") + var ErrUnknownDisk = errors.New("medialibrary: unknown disk") + var ErrUnsupportedImage = errors.New("medialibrary: unsupported image format") + func IsConvertible(mimeType string) bool + func SanitizeFileName(name string) string + func ValidatePath(p string) error + type CleanOptions struct + Disks []string + DryRun bool + OlderThan time.Duration + type CleanReport struct + Orphans []OrphanFile + Scanned int + type Collection struct + AcceptMIME []string + Conversions []Conversion + Disk string + MaxFiles int + MaxSize int64 + Name string + OwnerType string + Single bool + type Config struct + AfterCommit func(ctx context.Context, fn func(ctx context.Context)) + Collections []Collection + DefaultDisk string + DetectContentType func(head []byte) string + Disks map[string]Disk + Logger *slog.Logger + MaxPixels int64 + MaxSize int64 + Now func() time.Time + PathPrefix string + Queue Queue + Store Store + TempDir string + type Conversion struct + Background color.Color + Fit Fit + Format Format + Height int + Name string + Quality int + Width int + type ConversionJob struct + Conversions []string + MediaID uuid.UUID + type ConversionResult struct + Error string + Height int + MimeType string + Path string + Size int64 + Status ConversionStatus + UpdatedAt time.Time + Width int + type ConversionStatus string + const ConversionDone + const ConversionFailed + const ConversionPending + type CreateOptions struct + MaxFiles int + Replace bool + type Disk interface + Delete func(ctx context.Context, path string) error + Exists func(ctx context.Context, path string) (bool, error) + Open func(ctx context.Context, path string) (io.ReadCloser, error) + Put func(ctx context.Context, path string, r io.Reader, size int64, contentType string) error + URL func(path string) (string, error) + Walk func(ctx context.Context, prefix string, fn func(FileInfo) error) error + type FileInfo struct + ModTime time.Time + Path string + Size int64 + type Fit int + const FitContain + const FitCrop + const FitFill + func (f Fit) String() string + type Format int + const FormatJPEG + const FormatPNG + func (f Format) String() string + type Library struct + func New(cfg Config) (*Library, error) + func (l *Library) Add(ctx context.Context, owner Ref, collection string, r io.Reader, ...) (*Media, error) + func (l *Library) CleanOrphans(ctx context.Context, opts CleanOptions) (CleanReport, error) + func (l *Library) Delete(ctx context.Context, id uuid.UUID) error + func (l *Library) Get(ctx context.Context, id uuid.UUID) (*Media, error) + func (l *Library) List(ctx context.Context, owner Ref, collection string) ([]*Media, error) + func (l *Library) Open(ctx context.Context, m *Media, conversion string) (io.ReadCloser, error) + func (l *Library) RegenerateConversions(ctx context.Context, id uuid.UUID, names ...string) (*Media, error) + func (l *Library) Reorder(ctx context.Context, owner Ref, collection string, ids []uuid.UUID) error + func (l *Library) RunConversions(ctx context.Context, job ConversionJob) (*Media, error) + func (l *Library) SignedURL(ctx context.Context, m *Media, conversion string, ttl time.Duration) (string, error) + func (l *Library) URL(m *Media, conversion string) (string, error) + func (l *Library) UpdateProperties(ctx context.Context, id uuid.UUID, props map[string]any) (*Media, error) + type Media struct + Checksum string + Collection string + Conversions map[string]ConversionResult + CreatedAt time.Time + Disk string + FileName string + ID uuid.UUID + MimeType string + Name string + Order int + Owner Ref + Path string + Properties map[string]any + Size int64 + UpdatedAt time.Time + func (m *Media) Clone() *Media + func (m *Media) Validate() error + type OrphanFile struct + Disk string + Path string + Size int64 + type Queue interface + Enqueue func(ctx context.Context, job ConversionJob) error + type Ref struct + ID string + Type string + func (r Ref) String() string + type SignedURLer interface + SignedURL func(ctx context.Context, path string, ttl time.Duration) (string, error) + type Store interface + Create func(ctx context.Context, m *Media, opts CreateOptions) (replaced []*Media, err error) + Delete func(ctx context.Context, id uuid.UUID) (*Media, error) + Get func(ctx context.Context, id uuid.UUID) (*Media, error) + List func(ctx context.Context, owner Ref, collection string) ([]*Media, error) + PatchConversions func(ctx context.Context, id uuid.UUID, set map[string]ConversionResult, ...) (*Media, error) + Reorder func(ctx context.Context, owner Ref, collection string, ids []uuid.UUID, ...) error + UpdateProperties func(ctx context.Context, id uuid.UUID, props map[string]any, at time.Time) (*Media, error)