package lazymedia

import "golazy.dev/lazymedia"

Package lazymedia manages generated representations of stored files.

lazymedia does not own byte storage. It depends on a small FileStore interface so applications can back it with lazyfiles or another file service.

Use it for application-level derivatives such as thumbnails, previews, or converted media files. Keep original file metadata and storage backends in lazyfiles and lazystorage, then let lazymedia coordinate representation lookup and generation.

The append-only JSONL repository implementation lives in the golazy.dev/lazymedia/jsonl subpackage.

Constants

Types

type File

File is the minimal file metadata lazymedia needs from a file service.

type File struct {
	ID		string
	Filename	string
	ContentType	string
	Size		int64
	Metadata	json.RawMessage
}

type FileStore

FileStore is the minimal file service lazymedia needs.

type FileStore interface {
	Open(context.Context, string, ...any) (io.ReadCloser, File, []any, error)
	Put(context.Context, io.Reader, ...any) (File, []any, error)
	URL(context.Context, string, ...any) (string, []any, error)
}

type Media

Media resolves and generates file representations.

type Media struct {
	Files		FileStore
	Repository	Repository
	Processor	Processor
}
func (m *Media) URL

URL returns the URL for a ready or generated variant.

func (m *Media) URL(ctx context.Context, request Request, options ...any) (string, []any, error)
func (m *Media) Variant

Variant returns a ready variant, generating it when missing or requested.

func (m *Media) Variant(ctx context.Context, request Request, options ...any) (File, []any, error)

type Repository

Repository stores variant relationships.

type Repository interface {
	FindVariant(context.Context, string, string, ...any) (Variant, []any, error)
	SaveVariant(context.Context, Variant, ...any) (Variant, []any, error)
	DeleteVariant(context.Context, string, string, ...any) ([]any, error)
}

type Result

Result is the generated file body and metadata returned by processors.

type Result struct {
	Body		io.Reader
	ContentType	string
	Filename	string
	Options		[]any
}

type Spec

Spec supplies opaque app-defined JSON for the requested representation.

type Spec struct {
	JSON json.RawMessage
}

type Variant

Variant identifies a generated representation of a source file.

type Variant struct {
	SourceFileID	string		`json:"source_file_id"`
	VariantKey	string		`json:"variant_key"`
	Spec		json.RawMessage	`json:"spec,omitempty"`
	OutputFileID	string		`json:"output_file_id,omitempty"`
	Status		string		`json:"status,omitempty"`
	Error		string		`json:"error,omitempty"`
	CreatedAt	time.Time	`json:"created_at,omitempty"`
	UpdatedAt	time.Time	`json:"updated_at,omitempty"`
}

Directories

Path Synopsis
lazymedia/jsonl Package jsonl stores lazymedia repository records in an append-only JSONL file.