Documentation
¶
Overview ¶
Package config loads, validates, and persists librarr's server configuration and runtime settings.
Index ¶
- Constants
- Variables
- func ImportModeKeepsPayload(mode string) bool
- func NormalizeBaseURL(raw string) string
- func NormalizeImportMode(mode string) string
- type Config
- func (c *Config) ActiveTorrentClient() string
- func (c *Config) EffectiveImportMode() string
- func (c *Config) HasAPIKey() bool
- func (c *Config) HasAudiobookshelf() bool
- func (c *Config) HasAuth() bool
- func (c *Config) HasBookTracker() bool
- func (c *Config) HasCalibre() bool
- func (c *Config) HasDeluge() bool
- func (c *Config) HasFlibusta() bool
- func (c *Config) HasKavita() bool
- func (c *Config) HasKomga() bool
- func (c *Config) HasOIDC() bool
- func (c *Config) HasOIDCProxyHeaders() bool
- func (c *Config) HasProwlarr() bool
- func (c *Config) HasQBittorrent() bool
- func (c *Config) HasSABnzbd() bool
- func (c *Config) HasTorrentClient() bool
- func (c *Config) HasTransmission() bool
- func (c *Config) HasZLibrary() bool
- func (c *Config) KeepsPayload() bool
- func (c *Config) ReloadSettingsFile()
Constants ¶
const ( ImportModeAuto = "" ImportModeMove = "move" ImportModeHardlink = "hardlink" ImportModeCopy = "copy" )
Import modes decide how an organized file gets from the download folder into the library.
- ImportModeMove consumes the download: the payload is gone from the download folder afterwards, so the torrent can no longer be seeded even when its record is kept in the client (a force-recheck drops it to 0%).
- ImportModeHardlink adds a second directory entry for the same data. The library and the download folder share the bytes, so seeding continues and no extra disk is used. Requires both paths to live on one filesystem; otherwise librarr falls back to a copy.
- ImportModeCopy duplicates the bytes. Seeding continues at the cost of twice the disk.
- ImportModeAuto (the default, and what an unrecognized value becomes) resolves from RemoveTorrentAfterImport: keeping torrents means the user wants them seedable, so imports hardlink; removing them means nothing needs the payload, so imports move.
Variables ¶
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 ImportModeKeepsPayload ¶ added in v1.3.0
ImportModeKeepsPayload reports whether mode leaves the downloaded payload in place, which is what a torrent needs in order to keep seeding after import.
func NormalizeBaseURL ¶ added in v1.2.0
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.
func NormalizeImportMode ¶ added in v1.3.0
NormalizeImportMode maps user input onto a supported import mode. Anything unrecognized (including an empty value) becomes ImportModeAuto, so a typo lands on the default rather than silently picking a mode nobody asked for.
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
KavitaEbookLibraryID string
KavitaMangaLibraryID 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
// How organized files reach the library: move, hardlink, copy, or empty
// for automatic. Only "move" consumes the download payload; the other two
// leave it where the download client wrote it so the torrent can keep
// seeding. Read it through EffectiveImportMode, which resolves the
// automatic case against RemoveTorrentAfterImport.
ImportMode string
// 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 (the wanted-list search loop)
SchedulerEnabled bool
SchedulerIntervalHours int
SchedulerAutoDownload bool
SchedulerMinScore int
// SchedulerItemDelaySeconds is the pause between two wanted items in one
// pass, to stay polite to the sources.
SchedulerItemDelaySeconds 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 is the global switch for replacing
// an existing file with a better format; each profile has its own
// upgrade flag under it. UpgradeKeepOldFiles leaves the superseded file
// (and its library row) in place instead of deleting it.
AutoUpgradeEnabled bool
UpgradeKeepOldFiles bool
// Rename on Import
RenameEnabled bool
RenamePattern string
// Author Monitoring. AuthorMonitorAutoAdd is the default for new
// monitored authors: put newly found works on the wanted list.
AuthorMonitorEnabled bool
AuthorCheckIntervalDays int
AuthorMonitorAutoAdd bool
// OpenLibraryURL is the Open Library origin the author monitor queries
// (override for a local mirror or a test stub).
OpenLibraryURL string
}
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
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) EffectiveImportMode ¶ added in v1.3.0
EffectiveImportMode is the mode imports actually run in. An explicit IMPORT_MODE always wins; otherwise the mode follows the one setting whose whole purpose is seeding, so keeping torrents is enough on its own to keep them seedable.
func (*Config) HasAudiobookshelf ¶
HasAudiobookshelf returns true if ABS is configured.
func (*Config) HasBookTracker ¶ added in v1.1.0
HasBookTracker returns true if BookTracker is configured and enabled.
func (*Config) HasCalibre ¶
HasCalibre returns true if Calibre library path is configured.
func (*Config) HasFlibusta ¶ added in v1.1.0
HasFlibusta returns true if Flibusta is configured and enabled.
func (*Config) HasOIDCProxyHeaders ¶ added in v1.1.2
HasOIDCProxyHeaders returns true when reverse-proxy SSO headers should be trusted.
func (*Config) HasProwlarr ¶
HasProwlarr returns true if Prowlarr is configured.
func (*Config) HasQBittorrent ¶
HasQBittorrent returns true if qBittorrent is configured.
func (*Config) HasSABnzbd ¶
HasSABnzbd returns true if SABnzbd is configured.
func (*Config) HasTorrentClient ¶ added in v1.1.3
HasTorrentClient returns true if any torrent download backend is configured.
func (*Config) HasTransmission ¶
HasTransmission returns true if Transmission is configured.
func (*Config) HasZLibrary ¶ added in v1.1.0
HasZLibrary returns true if Z-Library is configured and enabled.
func (*Config) KeepsPayload ¶ added in v1.3.0
KeepsPayload reports whether imports leave the download payload where the client wrote it.
func (*Config) ReloadSettingsFile ¶ added in v1.3.0
func (c *Config) ReloadSettingsFile()
ReloadSettingsFile re-applies the overrides stored in SettingsFile on top of the current values. It is what a fresh process does at start-up, exposed so tests (and tooling) can prove a persisted setting survives a restart.