libraries

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package libraries owns the one Library model (spec §1): the two built-in libraries (1 = Movies, 2 = TV Shows), plugin-kind libraries and owner filter-libraries, in one component-owned table. Frontends, the console and app wiring consume it through Service; nothing in a request path special-cases a library beyond a dispatch on its Source.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBuiltinLibrary refuses a mutation the two built-ins never take
	// (deletion). Renaming, sorting and hiding them is fine.
	ErrBuiltinLibrary = errors.New("libraries: built-in library cannot be deleted")
	// ErrInvalid is a rejected declaration: empty name, an unslugifiable
	// name, or a plugin library without both ids.
	ErrInvalid = errors.New("libraries: invalid library")
)

Functions

func LegacyConfigNames

func LegacyConfigNames(configJSON []byte) (movies, shows string, err error)

LegacyConfigNames extracts the pre-v0.3.8 library names from a raw config document (config.json bytes, or a cluster's shared server document): server.moviesLibraryName / server.tvShowsLibraryName. Missing keys come back empty; the config fields themselves are deleted, so this raw read is the only way the names survive (§1.3).

Types

type Options

type Options struct {
	Logger *slog.Logger
	Now    func() time.Time
}

Options configures the Service.

type PluginLibraryDecl

type PluginLibraryDecl struct {
	Name    string
	Present core.Presentations
}

PluginLibraryDecl is what a plugin kind asks for at install (§2.5): the default display name and presentation. Owner edits made after install win: an upsert of an existing (plugin, kind) never overwrites the stored name or presentation.

type Service

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

Service is the libraries store. List/Get are plain indexed reads of a table that holds one row per library, never per item, so no call scales with library size.

func New

func New(ctx context.Context, db *sql.DB, o Options) (*Service, error)

New seeds the two built-in libraries idempotently (§1.3) and returns the service. db must already be migrated (store.Migrate), which is how every component table is opened.

func (*Service) ByKey

func (s *Service) ByKey(ctx context.Context, key string) (core.Library, error)

ByKey returns one library by its immutable slug, or core.ErrNotFound.

func (*Service) CreateFilter

func (s *Service) CreateFilter(ctx context.Context, name string, f core.Filter, p core.Presentations) (core.Library, error)

CreateFilter saves an owner filter-library (§1.5): a named core.Filter over the TMDB catalogue. Only the filter's JSON-serialised fields persist; its runtime fields are injected at query time. The caller passes the zero Presentations for the console-only default (§15.3) and the owner opts in per protocol afterwards with SetPresent.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id core.LibraryID) error

Delete removes a filter or plugin library. Built-ins are refused: Movies and TV Shows exist forever. Plugin libraries are deleted only through plugin removal (§2.5), which calls this after purging the plugin's items.

func (*Service) Generation

func (s *Service) Generation() uint64

Generation changes on every library mutation; it feeds frontend.PageFreshness (§6.4).

func (*Service) Get

func (s *Service) Get(ctx context.Context, id core.LibraryID) (core.Library, error)

Get returns one library by id, or core.ErrNotFound.

func (*Service) List

func (s *Service) List(ctx context.Context) ([]core.Library, error)

List returns every library in display order. Clients list libraries on every section request, so reads come from an in-memory snapshot of the (one row per library) table, refreshed on local writes and every snapshotTTL.

func (*Service) MigrateConfigNames

func (s *Service) MigrateConfigNames(ctx context.Context, moviesName, showsName string) error

MigrateConfigNames performs the one-time §1.3 migration: non-empty legacy names become the names of libraries 1 and 2. It runs at most once per database (libraries_state), so app wiring may call it on every open with whatever the config file still carries; once the config is rewritten without the old keys it becomes a no-op, and an owner rename in between is never overwritten.

func (*Service) MigrateConfigRules

func (s *Service) MigrateConfigRules(ctx context.Context, rules []core.LibraryExclusion, visibilityDefault string) error

MigrateConfigRules performs the one-time migration of global catalog.exclusions and catalog.visibilityDefault into built-in libraries 1 (Movies) and 2 (TV Shows): rules scoped to one media type move only to that library, while unscoped ("mixed"/"") rules move to both. Runs at most once per database so later owner edits on either library are never reverted.

func (*Service) Rename

func (s *Service) Rename(ctx context.Context, id core.LibraryID, name string) error

Rename changes a library's display name. The key never changes.

func (*Service) SetHidden

func (s *Service) SetHidden(ctx context.Context, id core.LibraryID, hidden bool) error

SetHidden hides or shows a library in all clients; it stays in the console either way.

func (*Service) SetPresent

func (s *Service) SetPresent(ctx context.Context, id core.LibraryID, p core.Presentations) error

SetPresent sets how protocols expose a library (§6.2).

func (*Service) SetRules

func (s *Service) SetRules(ctx context.Context, id core.LibraryID, rules []core.LibraryExclusion, visibilityDefault string) error

SetRules validates and stores TMDB visibility rules and default visibility on a built-in or filter library. Rules on a single-type library are pinned to that library's media type.

func (*Service) SetSort

func (s *Service) SetSort(ctx context.Context, id core.LibraryID, sort int) error

SetSort sets a library's owner order in every client.

func (*Service) UpsertPluginLibrary

func (s *Service) UpsertPluginLibrary(ctx context.Context, pluginID, kindKey string, decl PluginLibraryDecl) (core.Library, error)

UpsertPluginLibrary returns the library for one plugin media kind, creating it on first install (§2.5). An existing library is returned untouched: the stored name and presentation are owner-owned after install and a later manifest never overwrites them.

Jump to

Keyboard shortcuts

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