config

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package config loads, validates, and persists librarr's server configuration and runtime settings.

Index

Constants

This section is empty.

Variables

View Source
var BaseURLSettingKeys = []string{
	"qb_url",
	"transmission_url",
	"prowlarr_url",
	"sabnzbd_url",
	"abs_url",
	"abs_public_url",
	"kavita_url",
	"kavita_public_url",
	"komga_url",
	"calibre_url",
	"flibusta_url",
}

BaseURLSettingKeys lists the settings.json keys that hold a service base URL — the subset of settings normalizeServiceURLs repairs at load time. The settings API normalizes the same keys on write, so the value the UI shows after a save matches the one the runtime will use.

Functions

func NormalizeBaseURL added in v1.2.0

func NormalizeBaseURL(raw string) string

NormalizeBaseURL cleans a service base URL that came from an env var or the settings file: trims whitespace and trailing slashes, and prepends "http://" when no scheme is present.

Issue #92: a scheme-less value such as "audiobookshelf:13378" reaches net/http as a relative URL, so every request against it fails with the opaque `unsupported protocol scheme ""`. The user-visible symptoms are a library page stuck on "Failed to load library" and an "abs scan failed" log line, neither of which points at the URL as the cause. Repairing the value once, at load time, fixes every consumer at once.

A non-http scheme is left alone — if someone configures "unix://…" that's their call, and mangling it into "http://unix://…" would be worse than the original error.

Types

type Config

type Config struct {
	// Server
	Port   int
	DBPath string

	// TrustedProxies lists CIDRs/IPs of reverse proxies whose forwarded
	// headers (X-Forwarded-Proto) may be trusted. Empty = trust none.
	TrustedProxies []string

	// qBittorrent
	QBUrl               string
	QBUser              string
	QBPass              string
	QBSavePath          string
	QBCategory          string
	QBAudiobookSavePath string
	QBAudiobookCategory string
	QBMangaSavePath     string
	QBMangaCategory     string

	// Prowlarr
	ProwlarrURL    string
	ProwlarrAPIKey string

	// File Organization
	FileOrgEnabled   bool
	EbookDir         string
	AudiobookDir     string
	MangaDir         string
	IncomingDir      string
	MangaIncomingDir string

	// Torznab
	TorznabAPIKey string

	// Anna's Archive
	AnnasArchiveDomain    string
	AnnasArchiveSecretKey string // AA account secret key for /dyn/api/fast_download.json

	// Sources is the runtime indexer-endpoint registry. Drivers read URLs,
	// mirrors, and per-site config from here instead of from hardcoded
	// constants. Always non-nil after Load() returns.
	Sources *sources.Registry

	// Circuit Breaker
	CircuitBreakerThreshold int
	CircuitBreakerTimeout   int // seconds

	// Download Settings
	MaxRetries          int
	RetryBackoffSeconds int

	// Search Filtering
	MinTorrentSizeBytes int64
	MaxTorrentSizeBytes int64

	// Library Import Targets
	CalibreLibraryPath     string
	CalibreURL             string
	KavitaURL              string
	KavitaUser             string
	KavitaPass             string
	KavitaLibraryPath      string
	KavitaMangaLibraryPath string
	ABSURL                 string
	ABSToken               string
	ABSLibraryID           string
	ABSEbookLibraryID      string

	// Authentication
	AuthUsername string
	AuthPassword string
	APIKey       string

	// Komga
	KomgaURL         string
	KomgaUser        string
	KomgaPass        string
	KomgaLibraryID   string
	KomgaLibraryPath string

	// ABS Public URL (for external links)
	ABSPublicURL string

	// Kavita Public URL (for external links)
	KavitaPublicURL string

	// SABnzbd (Usenet)
	SABnzbdURL      string
	SABnzbdAPIKey   string
	SABnzbdCategory string

	// Download client priority (lower = preferred)
	QBPriority  int
	SABPriority int

	// Post-import torrent handling
	RemoveTorrentAfterImport bool

	// Flibusta
	FlibustaURL     string
	FlibustaEnabled bool

	// Z-Library
	ZLibraryURL      string
	ZLibraryEmail    string
	ZLibraryPassword string
	ZLibraryEnabled  bool

	// ThePirateBay
	TPBEnabled bool

	// BookTracker
	BookTrackerURL     string
	BookTrackerUser    string
	BookTrackerPass    string
	BookTrackerEnabled bool

	// Search filtering
	ForeignLangFilter bool // filter out non-English titles (default: true for backward compat)

	// Feature toggles
	RateLimitEnabled bool
	MetricsEnabled   bool
	WebNovelEnabled  bool
	MangaDexEnabled  bool

	// lightnovel-crawler container name (for docker exec)
	LNCrawlContainer string

	// Settings persistence
	SettingsFile string

	// OIDC / SSO
	OIDCEnabled              bool
	OIDCProviderName         string
	OIDCIssuer               string
	OIDCClientID             string
	OIDCClientSecret         string
	OIDCRedirectURI          string
	OIDCAutoCreateUsers      bool
	OIDCDefaultRole          string
	OIDCRequireEmailVerified bool
	OIDCProxyHeaders         bool

	// Deluge
	DelugeURL      string
	DelugePassword string

	// Transmission
	TransmissionURL  string
	TransmissionUser string
	TransmissionPass string

	// TorrentClient explicitly selects the active torrent backend
	// ("qbittorrent" or "transmission"). Empty means auto-detect.
	TorrentClient string

	// User Agent
	UserAgent string

	// Webhooks (env-based defaults)
	WebhookURL  string
	WebhookType string // "discord" or "generic"

	// Scheduler
	SchedulerEnabled       bool
	SchedulerIntervalHours int
	SchedulerAutoDownload  bool
	SchedulerMinScore      int

	// Wishlist cleanup removes wishlist rows that are already present in the
	// library. It is intentionally opt-in and dry-run by default.
	WishlistCleanupEnabled       bool
	WishlistCleanupIntervalHours int
	WishlistCleanupDryRun        bool

	// Quality Profiles
	AutoUpgradeEnabled bool

	// Rename on Import
	RenameEnabled bool
	RenamePattern string

	// Author Monitoring
	AuthorMonitorEnabled    bool
	AuthorCheckIntervalDays int
}

Config holds all application configuration loaded from environment variables.

func Load

func Load() *Config

Load reads configuration from environment variables with sensible defaults, then applies overrides from the settings file (if present) so values saved from the UI persist across restarts.

func (*Config) ActiveTorrentClient added in v1.1.3

func (c *Config) ActiveTorrentClient() string

ActiveTorrentClient resolves which torrent backend handles torrents:

  • an explicit, configured TORRENT_CLIENT wins ("qbittorrent"/"qbit"/"qb" or "transmission");
  • otherwise qBittorrent is preferred for backward compatibility;
  • otherwise Transmission if it alone is configured;
  • else "" (no torrent client).

func (*Config) HasAPIKey

func (c *Config) HasAPIKey() bool

HasAPIKey returns true if API key auth is configured.

func (*Config) HasAudiobookshelf

func (c *Config) HasAudiobookshelf() bool

HasAudiobookshelf returns true if ABS is configured.

func (*Config) HasAuth

func (c *Config) HasAuth() bool

HasAuth returns true if session-based auth is configured.

func (*Config) HasBookTracker added in v1.1.0

func (c *Config) HasBookTracker() bool

HasBookTracker returns true if BookTracker is configured and enabled.

func (*Config) HasCalibre

func (c *Config) HasCalibre() bool

HasCalibre returns true if Calibre library path is configured.

func (*Config) HasDeluge

func (c *Config) HasDeluge() bool

HasDeluge returns true if Deluge is configured.

func (*Config) HasFlibusta added in v1.1.0

func (c *Config) HasFlibusta() bool

HasFlibusta returns true if Flibusta is configured and enabled.

func (*Config) HasKavita

func (c *Config) HasKavita() bool

HasKavita returns true if Kavita is configured.

func (*Config) HasKomga

func (c *Config) HasKomga() bool

HasKomga returns true if Komga is configured.

func (*Config) HasOIDC

func (c *Config) HasOIDC() bool

HasOIDC returns true if OIDC/SSO is configured.

func (*Config) HasOIDCProxyHeaders added in v1.1.2

func (c *Config) HasOIDCProxyHeaders() bool

HasOIDCProxyHeaders returns true when reverse-proxy SSO headers should be trusted.

func (*Config) HasProwlarr

func (c *Config) HasProwlarr() bool

HasProwlarr returns true if Prowlarr is configured.

func (*Config) HasQBittorrent

func (c *Config) HasQBittorrent() bool

HasQBittorrent returns true if qBittorrent is configured.

func (*Config) HasSABnzbd

func (c *Config) HasSABnzbd() bool

HasSABnzbd returns true if SABnzbd is configured.

func (*Config) HasTorrentClient added in v1.1.3

func (c *Config) HasTorrentClient() bool

HasTorrentClient returns true if any torrent download backend is configured.

func (*Config) HasTransmission

func (c *Config) HasTransmission() bool

HasTransmission returns true if Transmission is configured.

func (*Config) HasZLibrary added in v1.1.0

func (c *Config) HasZLibrary() bool

HasZLibrary returns true if Z-Library is configured and enabled.

Jump to

Keyboard shortcuts

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