media

package
v0.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package media defines the files the media library holds.

Index

Constants

This section is empty.

Variables

View Source
var ErrConflict = errors.New("media: conflicting update")

ErrConflict reports that the media item changed after the update was prepared.

View Source
var ErrInvalidAuthor = errors.New("media: invalid author")

ErrInvalidAuthor reports that a media item carries no author.

View Source
var ErrInvalidFile = errors.New("media: invalid file")

ErrInvalidFile reports that a media item names no stored file.

View Source
var ErrInvalidMime = errors.New("media: invalid mime type")

ErrInvalidMime reports that a media item carries no content type.

View Source
var ErrInvalidOrder = errors.New("media: invalid order")

ErrInvalidOrder reports that a sort direction is not one the library sorts in.

View Source
var ErrInvalidOrderBy = errors.New("media: invalid orderby")

ErrInvalidOrderBy reports that a sort column is not one the library sorts by.

View Source
var ErrInvalidType = errors.New("media: invalid type")

ErrInvalidType reports that a media kind is not one the library tells apart.

View Source
var ErrNotFound = errors.New("media: not found")

ErrNotFound reports that no media item exists for the requested ID.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	Type           Type
	Mimes          []string
	Authors        []uuid.UUID
	ExcludeAuthors []uuid.UUID
	Before         *time.Time
	After          *time.Time
	ModifiedBefore *time.Time
	ModifiedAfter  *time.Time
	Search         string
	OrderBy        OrderBy
	Order          Order
	Page           int
	PerPage        int
}

Filter narrows a media listing by type, content type prefix, author, date and search, sorted as it names.

type Listed added in v0.19.0

type Listed struct {
	Media
	AuthorName string
}

Listed is a media item as a listing carries it, beside its author's name.

type Media

type Media struct {
	ID          int64
	Type        Type
	File        string
	Title       string
	AltText     string
	Caption     string
	Description string
	MimeType    string
	Width       int
	Height      int
	Filesize    int64
	Sizes       Sizes
	AuthorID    uuid.UUID
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

Media is a stored upload with the descriptions the editor reads.

func New

func New(file, title, mimeType string, authorID uuid.UUID) (Media, error)

New returns a Media item over a stored file, typed after its content type.

type Order added in v0.19.0

type Order string

Order names a sort direction.

const (
	OrderAsc  Order = "asc"
	OrderDesc Order = "desc"
)

The directions a media listing can be sorted in.

func ParseOrder added in v0.19.0

func ParseOrder(raw string) (Order, error)

ParseOrder returns the direction named by raw, or ErrInvalidOrder.

type OrderBy added in v0.19.0

type OrderBy string

OrderBy names a column a media listing can be sorted by.

const (
	OrderByDate     OrderBy = "date"
	OrderByModified OrderBy = "modified"
	OrderByTitle    OrderBy = "title"
	OrderByAuthor   OrderBy = "author"
)

The columns a media listing can be sorted by.

func ParseOrderBy added in v0.19.0

func ParseOrderBy(raw string) (OrderBy, error)

ParseOrderBy returns the column named by raw, or ErrInvalidOrderBy.

type Sizes added in v0.19.0

type Sizes map[string]SubSize

Sizes holds a media item's sub-sizes keyed by size slug.

type Store

type Store interface {
	Create(ctx context.Context, m Media) (Media, error)
	ByID(ctx context.Context, id int64) (Media, error)
	ByIDs(ctx context.Context, ids []int64) ([]Media, error)
	List(ctx context.Context, f Filter) ([]Listed, int, error)
	Update(ctx context.Context, m Media, expectedUpdatedAt time.Time) (Media, error)
	Delete(ctx context.Context, id int64) (Media, error)
}

Store persists the media library.

type SubSize added in v0.19.0

type SubSize struct {
	File     string `json:"file"`
	Width    int    `json:"width"`
	Height   int    `json:"height"`
	MimeType string `json:"mime_type"`
	Filesize int64  `json:"filesize"`
}

SubSize is one stored copy of an upload at an image size, with its file, measurements and byte count.

type Type

type Type string

Type sorts a media item into the kinds the library tells apart.

const (
	TypeImage Type = "image"
	TypeFile  Type = "file"
)

The kinds of media the library tells apart.

func ParseType

func ParseType(raw string) (Type, error)

ParseType returns the kind named by raw, or ErrInvalidType.

Directories

Path Synopsis
Package mediatest runs one set of behaviour cases against any media.Store.
Package mediatest runs one set of behaviour cases against any media.Store.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL