Documentation
¶
Overview ¶
Package api is Mediarium's HTTP API: the routes the web interface and scripts use, plus the pipelines they start (search, grab, download, post-process, import) and the background jobs.
Package api serves the REST API the web UI talks to ("REST API served to the web UI") and, in production, the embedded frontend build alongside it so the whole app is one binary/one port.
Index ¶
- type BuiltinKeys
- type Server
- func (s *Server) AnnounceSetup()
- func (s *Server) MusicBrainz() *musicbrainz.Client
- func (s *Server) Routes() http.Handler
- func (s *Server) SetBuiltinKeys(k BuiltinKeys)
- func (s *Server) SetExitFunc(fn func())
- func (s *Server) SetOpenSubtitlesAPIKey(key string) error
- func (s *Server) SetOpenSubtitlesAccount(username, password string) error
- func (s *Server) SetTMDBAPIKey(key string) error
- func (s *Server) SetTraktClientID(id string) error
- func (s *Server) SetUpdatePublicKey(b64 string) error
- func (s *Server) StartAutomation() *automation.Scheduler
- func (s *Server) StartMonitor() (stop func())
- func (s *Server) StartUpdates() (stop func())
- func (s *Server) StartWatchdog() (stop func())
- func (s *Server) Subtitles() *subtitles.Client
- func (s *Server) TMDB() *metadata.Client
- func (s *Server) Trakt() *trakt.Client
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BuiltinKeys ¶
BuiltinKeys are the app-wide API keys an official release ships with, so users don't have to sign up for each service themselves. They are injected at build time (see cmd/app/main.go and the Dockerfile), never committed. A key the user enters in Settings always wins over the built-in one; on a release that has a built-in key the Settings UI simply hides the field.
type Server ¶
type Server struct {
Auth *auth.Service
Settings *settings.Store
IndexerRepo *indexers.Repo
Definitions *indexers.DefinitionStore // cached community indexer definitions
Cardigann *indexers.CardigannManager // runs definition-based indexers
ClientRepo *download.Repo
MovieRepo *library.Repo
QueueRepo *queue.Repo
VPNRepo *vpn.Repo
VPNManager *vpn.Manager
NotifyRepo *notify.Repo
QualityRepo *quality.Repo
Blocklist *blocklist.Repo
SubtitleAttempts *subtitles.AttemptRepo
SubtitleDismissed *subtitles.DismissRepo
SubtitleQuota *subtitles.QuotaRepo
Usage *usage.Tracker // requests and limit hits per third-party service
Problems *problems.Log // the log of real problems shown under Settings > System > Logs and errors (handlers_problems.go)
MediaServers *mediaservers.Repo
MusicRepo *music.Repo // artists, albums, tracks (the music module, music*.go)
LoginLimiter *auth.LoginLimiter
Monitor *monitor.Monitor // connectivity monitor (Usenet servers, indexers)
// contains filtered or unexported fields
}
func New ¶
func New(db *sql.DB, cfg config.Config, box *crypto.Box, defaultTMDBAPIKey, version string) (*Server, error)
New wires every module's repo/service together (api depends on the feature packages, not the reverse) and loads the current TMDB key from settings, if one's been configured.
defaultTMDBAPIKey is a fallback used only when the user hasn't set one in Settings — see cmd/app/main.go's buildDefaultTMDBAPIKey doc comment for why this exists (matching Radarr/Sonarr's "just works" experience without committing a real key to source control).
func (*Server) AnnounceSetup ¶
func (s *Server) AnnounceSetup()
AnnounceSetup writes the setup code to the log when no administrator exists yet. main calls it once at start.
func (*Server) MusicBrainz ¶
func (s *Server) MusicBrainz() *musicbrainz.Client
MusicBrainz returns the MusicBrainz client. There is one per server, so every caller shares its one-request-per-second limit and its cache.
func (*Server) Routes ¶
Routes builds the full handler: public onboarding/auth endpoints, then everything else behind session/API-key auth, then (in production) the embedded frontend for anything not under /api/.
func (*Server) SetBuiltinKeys ¶
func (s *Server) SetBuiltinKeys(k BuiltinKeys)
SetBuiltinKeys installs the built-in keys and applies each one to its client unless the user already configured their own. Call it once at startup, before serving requests.
func (*Server) SetExitFunc ¶
func (s *Server) SetExitFunc(fn func())
SetExitFunc sets what happens after a restore has been staged: the app must restart so the staged files are swapped in before the database is opened. main wires this to a graceful shutdown (the process exits 0 and the container's restart policy, e.g. `restart: unless-stopped`, starts it again). The default is a plain os.Exit(0). On a setup with no restart policy the user has to start Mediarium again by hand; the restore is applied on that next start either way. Tests replace it so they do not exit.
func (*Server) SetOpenSubtitlesAPIKey ¶
SetOpenSubtitlesAPIKey updates both the persisted setting and the live client.
func (*Server) SetOpenSubtitlesAccount ¶
SetOpenSubtitlesAccount stores the optional OpenSubtitles.com login. Empty values clear it.
func (*Server) SetTMDBAPIKey ¶
SetTMDBAPIKey updates both the persisted setting and the live client.
func (*Server) SetTraktClientID ¶
SetTraktClientID updates both the persisted setting and the live client. An empty id clears the person's own client ID and puts the built-in one (if this release ships one) back in use.
func (*Server) SetUpdatePublicKey ¶
SetUpdatePublicKey sets the key that signed releases are checked against (base64 of a raw ed25519 public key). An empty or unusable key leaves "Update now" switched off.
func (*Server) StartAutomation ¶
func (s *Server) StartAutomation() *automation.Scheduler
StartAutomation wires the missing/upgrade hunting loop and RSS-style latest-releases sync into the generic scheduler from internal/automation. Called once from cmd/app/main.go after the server is constructed.
func (*Server) StartMonitor ¶
func (s *Server) StartMonitor() (stop func())
StartMonitor starts the background connectivity monitor and returns the function that stops it. Called once from cmd/app/main.go.
func (*Server) StartUpdates ¶
func (s *Server) StartUpdates() (stop func())
StartUpdates starts the daily check for a new version, and the overnight install if it is switched on. It does nothing in safe mode. The returned function stops it.
func (*Server) StartWatchdog ¶
func (s *Server) StartWatchdog() (stop func())
StartWatchdog starts the self-check: every 30 seconds it asks the database and the web server whether they answer, and if either has failed for three minutes in a row it writes a note and exits with status 1, so the container's restart policy (or the service manager) starts a fresh process. The next start says so in the log. It also picks up the note a previous run left. The returned function stops it.
func (*Server) Subtitles ¶
Subtitles returns the current OpenSubtitles client, safe to call concurrently with SetOpenSubtitlesAPIKey.
Source Files
¶
- access.go
- automation.go
- automation_intervals.go
- automation_tv.go
- blocklist.go
- dashboard.go
- discover_similar.go
- dispatch.go
- doc.go
- download_guard.go
- etag.go
- fallback.go
- flaresolverr.go
- folders.go
- genres_job.go
- grab_claim.go
- grab_urls.go
- guard.go
- handlers_auth.go
- handlers_backup.go
- handlers_browse.go
- handlers_bulk.go
- handlers_bulk_music.go
- handlers_calendar.go
- handlers_connection_tests.go
- handlers_diagnostics.go
- handlers_files.go
- handlers_grab.go
- handlers_import.go
- handlers_import_run.go
- handlers_indexers.go
- handlers_library.go
- handlers_media_servers.go
- handlers_media_servers_signin.go
- handlers_metrics.go
- handlers_migrate.go
- handlers_movie_detail.go
- handlers_no_upgrade.go
- handlers_notify.go
- handlers_problems.go
- handlers_queue.go
- handlers_restart.go
- handlers_series.go
- handlers_series_search.go
- handlers_settings.go
- handlers_stats.go
- handlers_subtitles.go
- handlers_update.go
- handlers_usenet_servers.go
- handlers_users.go
- handlers_vpn.go
- handlers_wanted.go
- health.go
- housekeeping.go
- import_worker.go
- item_events.go
- keys.go
- library_disk.go
- library_remove.go
- modules.go
- monitor.go
- music.go
- music_cover.go
- music_discover.go
- music_files.go
- music_follow.go
- music_import.go
- music_library.go
- music_profiles.go
- music_search.go
- notify_items.go
- pick_key.go
- pipeline.go
- pipeline_cancel.go
- pipeline_music.go
- pipeline_tv.go
- plain_failure.go
- preferred_language.go
- problems_hooks.go
- profile_validate.go
- profiles.go
- progress.go
- queue_control.go
- replaced_file.go
- respond.go
- robots.go
- search_answer.go
- secret_binding.go
- security.go
- server.go
- settings_validate.go
- setup.go
- sources.go
- static.go
- subtitles_auto.go
- subtitles_quota.go
- torrent_engine.go
- torrents_toggle.go
- update_check.go
- update_install.go
- update_runtime.go
- upstream.go
- usage.go
- validate.go
- validate_extra.go
- wanted_rules.go
- watchdog.go