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 ¶
- Variables
- func LegacyConfigNames(configJSON []byte) (movies, shows string, err error)
- type Options
- type PluginLibraryDecl
- type Service
- func (s *Service) ByKey(ctx context.Context, key string) (core.Library, error)
- func (s *Service) CreateFilter(ctx context.Context, name string, f core.Filter, p core.Presentations) (core.Library, error)
- func (s *Service) Delete(ctx context.Context, id core.LibraryID) error
- func (s *Service) Generation() uint64
- func (s *Service) Get(ctx context.Context, id core.LibraryID) (core.Library, error)
- func (s *Service) List(ctx context.Context) ([]core.Library, error)
- func (s *Service) MigrateConfigNames(ctx context.Context, moviesName, showsName string) error
- func (s *Service) MigrateConfigRules(ctx context.Context, rules []core.LibraryExclusion, visibilityDefault string) error
- func (s *Service) Rename(ctx context.Context, id core.LibraryID, name string) error
- func (s *Service) SetHidden(ctx context.Context, id core.LibraryID, hidden bool) error
- func (s *Service) SetPresent(ctx context.Context, id core.LibraryID, p core.Presentations) error
- func (s *Service) SetRules(ctx context.Context, id core.LibraryID, rules []core.LibraryExclusion, ...) error
- func (s *Service) SetSort(ctx context.Context, id core.LibraryID, sort int) error
- func (s *Service) UpsertPluginLibrary(ctx context.Context, pluginID, kindKey string, decl PluginLibraryDecl) (core.Library, error)
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 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 ¶
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) 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 ¶
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 ¶
Generation changes on every library mutation; it feeds frontend.PageFreshness (§6.4).
func (*Service) List ¶
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 ¶
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) SetHidden ¶
SetHidden hides or shows a library in all clients; it stays in the console either way.
func (*Service) SetPresent ¶
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) 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.