package lazymedia ¶
import "golazy.dev/lazymedia"
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 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 OutputFilename ¶
OutputFilename requests a filename for the generated file.
type OutputFilename struct {
Name string
}
type Processor ¶
Processor generates a representation for a source file.
type Processor interface {
Process(context.Context, Source, Request, ...any) (Result, []any, error)
}
type ProcessorFunc ¶
ProcessorFunc adapts a function to Processor.
type ProcessorFunc func(context.Context, Source, Request, ...any) (Result, []any, error)
func (fn ProcessorFunc) Process ¶
func (fn ProcessorFunc) Process(ctx context.Context, source Source, request Request, options ...any) (Result, []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"`
}
type VariantKey ¶
VariantKey selects a named representation.
type VariantKey struct {
Key string
}
Directories ¶
| Path | Synopsis |
|---|---|
| lazymedia/jsonl | Package jsonl stores lazymedia repository records in an append-only JSONL file. |
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.