* feat(nodeconfig): harden config watcher for integrated-mode use - RequestReload(): non-blocking, coalescing reload nudge that runs on the poll goroutine, so concurrent requests can never swap a stale snapshot over a newer one (unlike ForceReload from request handlers) - Skip OnChange callbacks when the reloaded config is deep-equal to the previous one, so the 60s poll doesn't fire rebuild/log callbacks on no-op reloads - Add RedisURL to BootstrapOverrides; previously a reload clobbered an env-provided Redis URL in the live config - Split reload into fetchSettings/applySettings and add unit tests Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(config): hot-reload config watcher in integrated mode Start nodeconfig.Watcher in integrated/api mode (previously only proxy/ transcode worker modes hot-reloaded). Expose the live config to the API and jellycompat routers via func-typed LiveConfig/OnConfigChange fields with nil fallbacks to the startup snapshot, and wire the admin settings update hook to RequestReload so same-process changes apply immediately even without Redis. No consumer reads the live config yet — conversions land separately. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(admin): truthful restart-required banner for settings saves The settings UI showed 'restart required' after every save regardless of the key. The backend now classifies each key via a central registry (internal/config/restart_keys.go) and PUT /admin/settings/{key} reports restart_required per key; useSettingsForm only raises the banner when a saved key actually needs a restart (and keeps it raised until restart). The registry is conservative: every currently startup-frozen key is marked restart-required; subsequent hot-reload conversions shrink it. Settings read live from the settings repo (branding, overlays, markers, download.*, ...) default to no-restart. DownloadSettings/OverlaySettings drop their hardcoded restartRequired={false} special-casing. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(logging): hot-reload server.log_level and server.log_quiet Share one slog.LevelVar across the handler chain and make logfilter.Handler's quiet-prefix list an atomic pointer shared with WithAttrs/WithGroup clones (New previously returned the inner handler unwrapped when the quiet list was empty, leaving nothing to update). The integrated-mode config watcher now applies both settings live; their keys leave the restart-required registry. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(auth): hot-reload access/refresh token expiries JWTService stores expiries as atomics with a SetExpiries hook; all three instances (main API, ABS compat, jellycompat) re-apply them on config reload. Applies to newly issued tokens; outstanding tokens keep their original expiry. The JWT secret stays fixed for the process lifetime. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(playback): read transcode config live at session start The playback and stream handlers pull ffmpeg path / hwaccel / transcode dir from the live config when starting a transcode or extracting subtitles, instead of values frozen at router construction. Each session snapshots the config once so its output dir and binary stay consistent. Also fixes a real bug: playback.hw_device was parsed into the config but never wired into the integrated-mode handler, so local transcodes always ran with an empty HWDevice while transcode nodes honored it. playback.transcode_dir leaves the restart-required registry (the handler is its only consumer); ffmpeg_path/hw_accel stay restart-required until scanner/chapterthumbs/audiobook consumers convert. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(jellycompat): read compat identity settings live per request System/Auth handlers take a config provider instead of the startup snapshot, so jellyfin_compat.public_url, .server_name, and .emulated_server_version apply without restart. server_id stays restart-required (generate-once, baked into the resource mapper), as do the session-store TTLs. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(scanner,metadata,mdblist): hot-reload worker pools and API key scanner.workers, matcher.workers/batch_size, metadata.cache_images, and mdblist.api_key convert to atomic fields with setters wired to the config watcher. Worker counts apply on the next scan/match cycle (the loops read them per cycle); the MDBList key applies to the next request. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(ai): hot-reload AI connection, models, toggles, and quotas The shared llm.Client holds its config behind an atomic pointer (UpdateConfig; each request snapshots once), and the subtitle/metadata AI services gain UpdateConfig plus setters on the translator (batching) and Whisper transcriber (ffmpeg path, chunk seconds). The router derives their configs from shared helpers used both at construction and in OnConfigChange callbacks, re-evaluating the chat-only-gateway transcribe guard on each reload and warning only when it newly fires. Everything on the AI Services page now applies without restart except ai.max_concurrent_jobs (fixed-capacity dispatch semaphore). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(playback): wire transcode_enabled; remove dead playback/scanner knobs playback.transcode_enabled was parsed into the config but the resolver always received a hardcoded true — the admin toggle did nothing. It now reads the live config per playback start, so disabling transcodes applies without restart. Remove settings that were wired to nothing so 'save + restart' stops pretending: playback.allow_hevc_encoding (resolver field never assigned), playback.transcode_ahead_segments and playback.segment_duration (parsed, never consumed — segment duration is per-session from the client), scanner.file_removal_grace (DeleteMissing is never called). UI fields removed and the config struct fields pruned so they don't resurrect; YAML import still tolerates the legacy keys. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
163 lines
4.9 KiB
Go
163 lines
4.9 KiB
Go
package jellycompat
|
|
|
|
import (
|
|
"context"
|
|
"io/fs"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
|
|
"github.com/Silo-Server/silo-server/internal/auth"
|
|
"github.com/Silo-Server/silo-server/internal/catalog"
|
|
"github.com/Silo-Server/silo-server/internal/clientip"
|
|
"github.com/Silo-Server/silo-server/internal/config"
|
|
"github.com/Silo-Server/silo-server/internal/nodepool"
|
|
"github.com/Silo-Server/silo-server/internal/recommendations"
|
|
"github.com/Silo-Server/silo-server/internal/scantrigger"
|
|
"github.com/Silo-Server/silo-server/internal/secret"
|
|
"github.com/Silo-Server/silo-server/internal/subtitles"
|
|
"github.com/Silo-Server/silo-server/internal/userstore"
|
|
)
|
|
|
|
// Dependencies holds the pluggable pieces used by the compat server.
|
|
type Dependencies struct {
|
|
Config *config.Config
|
|
// LiveConfig returns the current hot-reloaded config. May be nil (tests,
|
|
// worker modes); read through CurrentConfig(), which falls back to Config.
|
|
LiveConfig func() *config.Config
|
|
DB *pgxpool.Pool
|
|
SecretCipher *secret.Cipher // at-rest credential cipher (required when DB is set)
|
|
ClientIPResolver *clientip.Resolver
|
|
Now func() time.Time
|
|
TokenGenerator func() string
|
|
SessionStore *SessionStore
|
|
IDCodec *ResourceIDCodec
|
|
ImageCache *ImageCache
|
|
DeviceProfiles *DeviceProfileStore
|
|
PlaybackStore *PlaybackSessionStore
|
|
LoginResolver loginResolver
|
|
Authenticator *Authenticator
|
|
WebFS fs.FS
|
|
HTTPClient *http.Client
|
|
|
|
// Direct service dependencies (replaces Client)
|
|
ContentService ContentService
|
|
UserDataService UserDataService
|
|
AuthService *auth.Service
|
|
|
|
// Autoscan / admin compatibility support.
|
|
APIKeyValidator apiKeyValidator
|
|
APIKeyUserLoader apiKeyUserLoader
|
|
ScanQueue scantrigger.Queuer
|
|
|
|
// Catalog repos (for ContentService construction)
|
|
BrowseRepo *catalog.BrowseRepository
|
|
ItemRepo *catalog.ItemRepository
|
|
SeasonRepo *catalog.SeasonRepository
|
|
EpisodeRepo *catalog.EpisodeRepository
|
|
ProviderIDRepo *catalog.ProviderIDRepository
|
|
DetailSvc *catalog.DetailService
|
|
FolderRepo *catalog.FolderRepository
|
|
|
|
// Person repository
|
|
PersonRepo *catalog.PersonRepository
|
|
|
|
// Library poster presigning
|
|
PosterPresigner LibraryPosterPresigner
|
|
PresignTTL time.Duration
|
|
|
|
// Playback
|
|
SessionMgr SessionManagerInterface
|
|
FileResolver FilePathResolver
|
|
UserStoreProvider userstore.UserStoreProvider
|
|
AccessFilterFn AccessFilterResolver
|
|
NodePlanner nodepool.SessionPlanner
|
|
JWTSecret string
|
|
Recommender recommendations.Recommender
|
|
RecWorker *recommendations.Worker
|
|
|
|
// Settings (optional; reads server_settings for watched threshold, etc.)
|
|
SettingsRepo SettingsReader
|
|
|
|
// Subtitle support (optional)
|
|
SubtitleRepo subtitles.Repository // optional; downloaded subtitle support
|
|
S3Client subtitles.S3Client // optional
|
|
S3Bucket string // optional
|
|
}
|
|
|
|
// CurrentConfig returns the live config when hot reload is wired, falling
|
|
// back to the startup snapshot otherwise.
|
|
func (d *Dependencies) CurrentConfig() *config.Config {
|
|
if d.LiveConfig != nil {
|
|
if cfg := d.LiveConfig(); cfg != nil {
|
|
return cfg
|
|
}
|
|
}
|
|
return d.Config
|
|
}
|
|
|
|
// Server wraps the compat HTTP handler.
|
|
type Server struct {
|
|
cfg *config.Config
|
|
handler http.Handler
|
|
deps Dependencies
|
|
}
|
|
|
|
// NewServer creates a new Jellyfin-compatibility server.
|
|
func NewServer(cfg *config.Config) *Server {
|
|
return NewServerWithDependencies(NewDependencies(cfg))
|
|
}
|
|
|
|
// NewServerWithDependencies creates a new Jellyfin-compatibility server using explicit dependencies.
|
|
func NewServerWithDependencies(deps Dependencies) *Server {
|
|
deps = withDefaults(deps)
|
|
return &Server{
|
|
cfg: deps.Config,
|
|
handler: NewRouter(deps),
|
|
deps: deps,
|
|
}
|
|
}
|
|
|
|
// Handler returns the compat HTTP handler.
|
|
func (s *Server) Handler() http.Handler {
|
|
return s.handler
|
|
}
|
|
|
|
// HTTPServer builds an http.Server using the compat listen address.
|
|
func (s *Server) HTTPServer() *http.Server {
|
|
return &http.Server{
|
|
Addr: s.cfg.JellyfinCompat.Listen,
|
|
Handler: s.handler,
|
|
}
|
|
}
|
|
|
|
// Dependencies returns the resolved dependency set.
|
|
func (s *Server) Dependencies() Dependencies {
|
|
return s.deps
|
|
}
|
|
|
|
// SessionStore returns the compat session store for external revocation hooks.
|
|
func (s *Server) SessionStore() *SessionStore {
|
|
return s.deps.SessionStore
|
|
}
|
|
|
|
// StartBackgroundTasks starts background goroutines tied to the server lifecycle.
|
|
// Call this once after constructing the server; goroutines stop when ctx is cancelled.
|
|
func (s *Server) StartBackgroundTasks(ctx context.Context) {
|
|
if s.deps.DB != nil {
|
|
repo := NewSessionRepository(s.deps.DB, s.deps.SecretCipher)
|
|
StartSessionCleanup(ctx, repo, 1*time.Hour)
|
|
}
|
|
}
|
|
|
|
// NewDependencies fills in sensible defaults for optional compat dependencies.
|
|
func NewDependencies(cfg *config.Config) Dependencies {
|
|
return Dependencies{
|
|
Config: cfg,
|
|
Now: time.Now,
|
|
TokenGenerator: uuid.NewString,
|
|
}
|
|
}
|