golazy.dev golazy.dev / lazymedia Index | Files

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.

Constants

const StatusReady, StatusGenerating, StatusFailed

const (
	StatusReady		= "ready"
	StatusGenerating	= "generating"
	StatusFailed		= "failed"
)

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 LogRepository

LogRepository stores variant metadata in an append-only JSONL log.

type LogRepository struct {
	// contains filtered or unexported fields
}
func NewLogRepository

NewLogRepository opens or creates an append-only JSONL variant repository.

func NewLogRepository(path string) (*LogRepository, error)
func (r *LogRepository) DeleteVariant
func (r *LogRepository) DeleteVariant(ctx context.Context, sourceFileID, variantKey string, options ...any) ([]any, error)
func (r *LogRepository) FindVariant
func (r *LogRepository) FindVariant(ctx context.Context, sourceFileID, variantKey string, options ...any) (Variant, []any, error)
func (r *LogRepository) SaveVariant
func (r *LogRepository) SaveVariant(ctx context.Context, variant Variant, options ...any) (Variant, []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 Regenerate

Regenerate bypasses an existing ready variant and generates it again.

type Regenerate struct{}

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 Request

Request asks for a generated representation.

type Request struct {
	SourceFileID	string
	VariantKey	string
	Spec		json.RawMessage
}

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 Source

Source is an opened source file passed to processors.

type Source struct {
	File	File
	Body	io.ReadCloser
}

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"`
}