media

package module
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

modules/media

Official Lesstruct module: the media library — uploads, listing, AI image generation, and thumbnail variants.

Layout (module template)

module.go            # kernel.Module + Migrator (single registry-facing file)
migrations/          # {sqlite,postgresql,mysql}/000001_media.{up,down}.sql (embed)
api/                 # browser handlers (legacy envelope) + mocks
api/agent/           # Bearer-realm handlers (UPPER_SNAKE envelope) + dto + mocks
domain/              # service, processor, image providers, thumbnail (3.2d)
store/               # single-source repository on kernel.Dialect (3.2c)
admin/               # admin-shell manifest (media library entry)
testutil/            # kernel fixture for module tests

Handlers

Both auth realms are served from this module: api.MediaHandler (browser JWT/CSRF, legacy error:null envelope) and api/agent.MediaHandler (Bearer API key, UPPER_SNAKE envelope). Cursor pagination is shared via kernel/httpx. Core mounts the handlers explicitly — the surface spans three body-limit groups plus the dual-auth dispatch, which a single RouteProvider call cannot express — through structural MediaBrowserHandler/MediaAgentHandler interfaces in routes.go, so routes stay module-agnostic and paths never drift.

Migrations

Each module versions independently in its own schema_migrations_<module> table (see internal/database/modules.go), so modules install and upgrade without touching the core sequence. Module migrations must stay idempotent (CREATE TABLE IF NOT EXISTS): pre-module installs already carry tables extracted from the core sequence.

Documentation

Overview

Package media is the official media-library module: uploads, the media library, AI image generation, and thumbnail variants.

Index

Constants

View Source
const (
	// Name is the registry key for this module.
	Name = "media"

	// Version is the module version reported via Module.Version.
	Version = "0.1.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module is the media kernel module.

func New

func New(opts ...Option) *Module

New builds the module, adopting the composition root's wiring. Both realm handlers are built once here so routes serve the same instances.

func (*Module) AdminManifest

func (m *Module) AdminManifest() kernel.AdminExtensionManifest

AdminManifest declares this module's admin-shell extensions: the media library navigation entry.

func (*Module) AgentHandler

func (m *Module) AgentHandler() *agent.MediaHandler

AgentHandler exposes the Bearer-realm handler for core mounting, alongside the browser handler for the same per-route-limit reason.

func (*Module) BrowserHandler

func (m *Module) BrowserHandler() *api.MediaHandler

BrowserHandler exposes the JWT/CSRF-realm handler for core mounting. Core mounts it explicitly (rather than via RouteProvider) because the media surface spans three body-limit groups plus the dual-auth dispatch — a single RegisterRoutes call cannot express per-route body limits.

func (*Module) Init

func (m *Module) Init(_ kernel.Kernel) error

Init wires the module. The handlers are already built by New; Init only validates presence. Migration execution is core-driven (it needs the live *sql.DB, which modules never touch directly).

func (*Module) Migrations

func (m *Module) Migrations() fs.FS

Migrations returns the embedded migration filesystem, laid out per driver ({sqlite,postgresql,mysql}/NNN_name.{up,down}.sql). The core runner tracks each module in its own schema_migrations_<module> table.

func (*Module) Name

func (m *Module) Name() string

Name returns the registry key.

func (*Module) Optional

func (m *Module) Optional() []string

Optional lists soft dependencies. None.

func (*Module) Requires

func (m *Module) Requires() []string

Requires lists hard dependencies. Media references users loosely (owner IDs without foreign-key enforcement), so nothing is required.

func (*Module) Service

func (m *Module) Service() *mediadomain.Service

Service exposes the adopted domain service for composition-root wiring (importers, text generation, templates). It stays valid for the module's lifetime.

func (*Module) Shutdown

func (m *Module) Shutdown() error

Shutdown releases module resources. There are none beyond memory.

func (*Module) Version

func (m *Module) Version() string

Version returns the module version.

type Option

type Option func(*Module)

Option configures a Module. The composition root supplies every option; direct construction without options yields a standalone module that serves nothing (handlers built over nil dependencies must not be invoked).

func WithAgentRoles

func WithAgentRoles(roles agent.RoleCapabilities) Option

WithAgentRoles attaches the role registry for the agent upload gate. It is a separate option (rather than sharing WithRoles) because the two api packages own their seams independently; core satisfies both with one adapter.

func WithImageGeneration

func WithImageGeneration(service mediadomain.ImageGenerationService) Option

WithImageGeneration adopts the AI image provider (composition root, nil when unconfigured). Without one the generate endpoint answers 503 not_configured (fail closed).

func WithLogger

func WithLogger(logger kernel.Logger) Option

WithLogger attaches the module logger. Without one handler failures are dropped (discard sink).

func WithRoles

func WithRoles(roles api.RoleCapabilities) Option

WithRoles attaches the role registry for the browser upload/generate/delete gates. Without one every authenticated caller may manage media (the legacy behavior).

func WithService

func WithService(service *mediadomain.Service) Option

WithService adopts the media domain service (composition root). The same instance backs the browser and agent handlers so hashing, dedup, WebP conversion, and thumbnail variants run identically in both realms.

Directories

Path Synopsis
Package admin owns this module's admin-shell manifest: the declarative UI the single admin SPA renders for media.
Package admin owns this module's admin-shell manifest: the declarative UI the single admin SPA renders for media.
api
Package store is the single-source media repository: one implementation against *sql.DB plus a kernel Dialect, replacing the three per-driver copies.
Package store is the single-source media repository: one implementation against *sql.DB plus a kernel Dialect, replacing the three per-driver copies.
Package testutil provides the kernel fixture module tests run against.
Package testutil provides the kernel fixture module tests run against.

Jump to

Keyboard shortcuts

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