Documentation
¶
Overview ¶
Package server — Content-Security-Policy construction.
The CSP is computed once at startup from the embedded HTML entrypoints rather than hardcoded, so the inline <head> script — the anti-FOUC <script data-theme-init> IIFE (@cplieger/ui-primitives' themeInitSnippet output) — is allowed by an exact sha256 hash. Under default-src 'self' an inline script has no exception, so without a matching script-src hash the browser blocks it and the page flashes the wrong theme before the stylesheets load. Deriving the hash from the embedded file means an edit (even a whitespace-only reformat) needs no hand-updated constant. (The former second inline script, the importmap, is gone: cmd/bundle resolves every bare specifier at build time.)
Package server provides the HTTP server and history poller for subtitle management.
The package is split across several files by concern:
- server.go — New() constructor and lifecycle (this file)
- server_types.go — Server struct, embedded dep groups, Option functions
- server_init.go — initHandlers (handler family construction)
- middleware.go — requireAuth / requireRole / requireConfigured
- routes.go — routeGroup + registerRoutes + permission model
- poller.go — Sonarr/Radarr history polling + import processing
- scheduler.go — full-scan pipeline + DB maintenance + auth cleanup
- *_handlers.go — per-concern HTTP handler families
Index ¶
- type Metrics
- type Option
- func WithArrClientFactories(newSonarr func(baseURL, apiKey string) (api.SonarrClient, error), ...) Option
- func WithConfig(cfg api.ConfigProvider) Option
- func WithConfigLoader(l api.ConfigLoader) Option
- func WithDefaultConfig(cfg []byte) Option
- func WithLogSetup(f func(level, format string)) Option
- func WithMetrics(m Metrics) Option
- func WithPort(port int) Option
- func WithSchema(f api.SchemaFunc) Option
- func WithSubtitleProc(p api.SubtitleProcessor) Option
- func WithWire(w wiring.Func) Option
- type Server
- func (s *Server) AdminHandler() http.Handler
- func (s *Server) RecordPersistentAlert(source, msg string)
- func (s *Server) SetAuth(store authstore.AuthStore, rl ratelimit.Checker) error
- func (s *Server) Start(ctx context.Context, onReady func())
- func (s *Server) StartUnconfigured(ctx context.Context, onReady func())
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Metrics ¶
type Metrics interface {
RecordSearch(provider api.ProviderID, dur time.Duration, err error)
RecordDownload(provider api.ProviderID, err error)
AdaptiveSkip()
RecordEmbeddedDetectorError()
RecordScan(items, found int, dur time.Duration)
RecordImport(source api.PollKey)
RecordHTTP(method, path string, status int, d time.Duration)
RecordPanic()
TotalSearches() int64
Handler() http.HandlerFunc
// Store observability (Requirement 17).
RecordStoreFileSize(bytes int64)
RecordStoreFreelistBytes(bytes int64)
RecordReconcile(deleted int, reset int64, dur time.Duration)
RecordBackupSuccess(dur time.Duration)
// Mode observability: 1 when a valid configuration is active, 0 unconfigured.
SetConfigured(ok bool)
// Poll-cursor durability: count of cursors whose durable persist is failing.
SetPollCursorsDirty(n int)
}
Metrics is the observability interface consumed by the server package.
type Option ¶
type Option func(*Server)
Option configures a Server during construction.
func WithArrClientFactories ¶ added in v0.1.106
func WithArrClientFactories( newSonarr func(baseURL, apiKey string) (api.SonarrClient, error), newRadarr func(baseURL, apiKey string) (api.RadarrClient, error), ) Option
WithArrClientFactories sets the factories for creating Sonarr and Radarr API clients, used by hot reload and config-save connectivity checks.
func WithConfig ¶
func WithConfig(cfg api.ConfigProvider) Option
WithConfig sets the initial configuration. Config-only by design: arr clients (and every other config-derived capability) are constructed by activation in both boot modes, never handed in from outside.
func WithConfigLoader ¶
func WithConfigLoader(l api.ConfigLoader) Option
WithConfigLoader sets the config loader.
func WithDefaultConfig ¶
WithDefaultConfig sets the embedded default config bytes.
func WithLogSetup ¶ added in v0.1.148
WithLogSetup injects the process-global logging setup so activation can re-apply a changed logging section without a restart. Owned by the composition root (main.go's setupLogging).
func WithSchema ¶
func WithSchema(f api.SchemaFunc) Option
WithSchema sets the config schema function.
func WithSubtitleProc ¶
func WithSubtitleProc(p api.SubtitleProcessor) Option
WithSubtitleProc sets the subtitle processor.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the main application server.
func (*Server) AdminHandler ¶ added in v0.1.148
AdminHandler returns the admin-plane handler: a one-route mux serving POST /api/admin/bootstrap, wrapped in the same access-log/request-ID and panic-recovery middleware the TCP mux uses (the body limit is inside the handler via webhttp.DecodeBody, exactly as on the TCP plane). main.go serves it on a second http.Server bound to the Unix socket in the 0700 directory config.AdminSocketDir — kernel socket custody replaces the former requireLocalhost peer-address check, so the zero-credential bootstrap channel is unreachable over every TCP path (netns-sharing peers and proxied clients included). Both configured and unconfigured server modes expose it.
func (*Server) RecordPersistentAlert ¶ added in v0.1.148
RecordPersistentAlert records a manually-dismissable operator alert. Exported for the composition root: main.go owns the admin-socket listener lifecycle and reports its failure as a persistent alert here (degraded mode — bootstrap unavailable — rather than fatal).
func (*Server) SetAuth ¶
SetAuth configures authentication dependencies on the server. WebAuthn and OIDC are deliberately absent from the signature: both are config-derived capabilities that activation builds into the live snapshot, resolved per request through the handler's resolver funcs. SetAuth returns an error only when the assembled authenticator configuration is rejected by the auth library's construction validation (a programming error, not runtime state).
func (*Server) Start ¶
Start activates the boot config and starts the HTTP server. Cold boot and hot first-save go through the SAME activation operation (activate.go); the only cold-boot special case is the failure policy — an activation failure falls back to settings mode instead of refusing to serve, so a config that boots today keeps booting.
func (*Server) StartUnconfigured ¶
StartUnconfigured starts the HTTP server without a valid config.
Source Files
¶
- activate.go
- activity.go
- activity_cancel.go
- admin_bootstrap.go
- backup.go
- config_handlers.go
- coverage_count.go
- events.go
- helpers.go
- lifecycle.go
- manual.go
- middleware.go
- poller.go
- poster_client.go
- reload.go
- routes.go
- scan_handlers.go
- scheduler.go
- scheduler_scan.go
- security.go
- server.go
- server_init.go
- server_types.go
- staticcache.go
- storemetrics.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package activity provides concurrent-safe activity and alert tracking for the subflux UI status indicator.
|
Package activity provides concurrent-safe activity and alert tracking for the subflux UI status indicator. |
|
Package authhandlers provides shared types and utilities for the server's authentication handler cluster: login, WebAuthn, OIDC, admin user management, and security management (password change, API keys, passkeys).
|
Package authhandlers provides shared types and utilities for the server's authentication handler cluster: login, WebAuthn, OIDC, admin user management, and security management (password change, API keys, passkeys). |
|
Package confighandlers provides HTTP handlers for configuration CRUD operations: get, save, reset, schema, and path validation.
|
Package confighandlers provides HTTP handlers for configuration CRUD operations: get, save, reset, schema, and path validation. |
|
Package coverage provides pure computation functions for subtitle coverage analysis.
|
Package coverage provides pure computation functions for subtitle coverage analysis. |
|
Package coveragehandlers provides HTTP handlers for the /api/coverage/* endpoints.
|
Package coveragehandlers provides HTTP handlers for the /api/coverage/* endpoints. |
|
Package events is subflux's typed server-sent-events layer: the sealed Event/EventData types the app publishes, marshaled onto the shared webhttp/sse broadcast hub.
|
Package events is subflux's typed server-sent-events layer: the sealed Event/EventData types the app publishes, marshaled onto the shared webhttp/sse broadcast hub. |
|
Package filehandlers provides HTTP handlers for the /api/files/* endpoints.
|
Package filehandlers provides HTTP handlers for the /api/files/* endpoints. |
|
Package httphelpers provides shared HTTP handler prelude helpers used across server sub-packages.
|
Package httphelpers provides shared HTTP handler prelude helpers used across server sub-packages. |
|
Package manualops implements the business logic for manual subtitle search and download operations.
|
Package manualops implements the business logic for manual subtitle search and download operations. |
|
Package mediahandlers provides HTTP handlers for the /api/media/* endpoints.
|
Package mediahandlers provides HTTP handlers for the /api/media/* endpoints. |
|
Package polling provides the history-polling subsystem for Sonarr/Radarr import events and the write-through poll timestamp cache.
|
Package polling provides the history-polling subsystem for Sonarr/Radarr import events and the write-through poll timestamp cache. |
|
Package previewhandlers provides HTTP handlers for the video/subtitle preview and poster proxy endpoints.
|
Package previewhandlers provides HTTP handlers for the video/subtitle preview and poster proxy endpoints. |
|
Package queryhandlers provides read-only HTTP query handlers: subtitle state, backoff, manual locks, providers, parsed config, score simulation, and dashboard stats.
|
Package queryhandlers provides read-only HTTP query handlers: subtitle state, backoff, manual locks, providers, parsed config, score simulation, and dashboard stats. |
|
Package resolve is the one home for typed-reference resolution (S7): it maps the wire references — FileRef (one stored subtitle file) and MediaRef (the arr-known video of a media item) — to absolute filesystem paths using server-derived facts only.
|
Package resolve is the one home for typed-reference resolution (S7): it maps the wire references — FileRef (one stored subtitle file) and MediaRef (the arr-known video of a media item) — to absolute filesystem paths using server-derived facts only. |
|
Package scanning implements the full-scan orchestration engine.
|
Package scanning implements the full-scan orchestration engine. |
|
Package scheduler provides the periodic full-scan pipeline, DB maintenance, and auth cleanup scheduling for the subflux server.
|
Package scheduler provides the periodic full-scan pipeline, DB maintenance, and auth cleanup scheduling for the subflux server. |
|
Package serveradapter provides adapter types that bridge the server's activity, alert, and event subsystems to the interfaces consumed by the scanning and manualops packages.
|
Package serveradapter provides adapter types that bridge the server's activity, alert, and event subsystems to the interfaces consumed by the scanning and manualops packages. |
|
Package showskip provides a TTL-based cache for show-level subtitle pre-check results.
|
Package showskip provides a TTL-based cache for show-level subtitle pre-check results. |
|
Package subtitlepath owns the subtitle-scoped file deletion gate: the delete capability check from the subtitle-extension authority (internal/subtitleext) layered in front of the generic media-root containment delete (config.RemoveUnderRoot).
|
Package subtitlepath owns the subtitle-scoped file deletion gate: the delete capability check from the subtitle-extension authority (internal/subtitleext) layered in front of the generic media-root containment delete (config.RemoveUnderRoot). |
|
Package synchandlers provides HTTP handlers for subtitle sync operations (audio-based sync and manual offset adjustment).
|
Package synchandlers provides HTTP handlers for subtitle sync operations (audio-based sync and manual offset adjustment). |