Files
zurg/internal/config/types.go

233 lines
6.1 KiB
Go

package config
import "os"
type ConfigInterface interface {
GetConfig() ZurgConfig
GetVersion() string
GetToken() string
GetNumOfWorkers() int
GetRefreshEverySecs() int
GetRepairEveryMins() int
EnableRepair() bool
GetHost() string
GetPort() string
GetUsername() string
GetPassword() string
GetProxy() string
GetDirectories() []string
MeetsConditions(directory, torrentName string, torrentSize int64, torrentIDs, fileNames []string, fileSizes []int64) bool
GetOnLibraryUpdate() string
GetNetworkBufferSize() int
EnableRetainFolderNameExtension() bool
EnableRetainRDTorrentName() bool
ShouldIgnoreRenames() bool
ShouldServeFromRclone() bool
ShouldForceIPv6() bool
GetApiTimeoutSecs() int
GetDownloadTimeoutSecs() int
GetRetriesUntilFailed() int
GetRateLimitSleepSecs() int
ShouldDeleteRarFiles() bool
GetDownloadsEveryMins() int
GetDownloadsLimit() int
GetDumpTorrentsEveryMins() int
GetPlayableExtensions() []string
GetTorrentsCount() int
}
type ZurgConfig struct {
Version string `yaml:"zurg" json:"-"`
Token string `yaml:"token" json:"-"`
ApiTimeoutSecs int `yaml:"api_timeout_secs" json:"api_timeout_secs"`
CanRepair bool `yaml:"enable_repair" json:"enable_repair"`
DeleteRarFiles bool `yaml:"auto_delete_rar_torrents" json:"auto_delete_rar_torrents"`
DownloadsEveryMins int `yaml:"downloads_every_mins" json:"downloads_every_mins"`
DownloadsLimit int `yaml:"downloads_limit" json:"downloads_limit"`
DumpTorrentsEveryMins int `yaml:"dump_torrents_every_mins" json:"dump_torrents_every_mins"`
DownloadTimeoutSecs int `yaml:"download_timeout_secs" json:"download_timeout_secs"`
ForceIPv6 bool `yaml:"force_ipv6" json:"force_ipv6"`
Host string `yaml:"host" json:"host"`
IgnoreRenames bool `yaml:"ignore_renames" json:"ignore_renames"`
NetworkBufferSize int `yaml:"network_buffer_size" json:"network_buffer_size"`
NumOfWorkers int `yaml:"concurrent_workers" json:"concurrent_workers"`
OnLibraryUpdate string `yaml:"on_library_update" json:"on_library_update"`
Password string `yaml:"password" json:"password"`
PlayableExtensions []string `yaml:"addl_playable_extensions" json:"addl_playable_extensions"`
Port string `yaml:"port" json:"port"`
Proxy string `yaml:"proxy" json:"proxy"`
RateLimitSleepSecs int `yaml:"rate_limit_sleep_secs" json:"rate_limit_sleep_secs"`
RefreshEverySecs int `yaml:"check_for_changes_every_secs" json:"check_for_changes_every_secs"`
RepairEveryMins int `yaml:"repair_every_mins" json:"repair_every_mins"`
RetainFolderNameExtension bool `yaml:"retain_folder_name_extension" json:"retain_folder_name_extension"`
RetainRDTorrentName bool `yaml:"retain_rd_torrent_name" json:"retain_rd_torrent_name"`
RetriesUntilFailed int `yaml:"retries_until_failed" json:"retries_until_failed"`
ServeFromRclone bool `yaml:"serve_from_rclone" json:"serve_from_rclone"`
TorrentsCount int `yaml:"get_torrents_count" json:"get_torrents_count"`
Username string `yaml:"username" json:"username"`
}
func (z *ZurgConfig) GetConfig() ZurgConfig {
return *z
}
func (z *ZurgConfig) GetToken() string {
return z.Token
}
func (z *ZurgConfig) GetHost() string {
if z.Host == "" {
return "[::]"
}
return z.Host
}
func (z *ZurgConfig) GetPort() string {
if os.Getenv("PORT") != "" {
return os.Getenv("PORT")
}
if z.Port == "" {
return "9999"
}
return z.Port
}
func (z *ZurgConfig) GetUsername() string {
return z.Username
}
func (z *ZurgConfig) GetPassword() string {
return z.Password
}
func (z *ZurgConfig) GetProxy() string {
if os.Getenv("PROXY") != "" {
return os.Getenv("PROXY")
}
return z.Proxy
}
func (z *ZurgConfig) GetNumOfWorkers() int {
if z.NumOfWorkers == 0 {
return 20
}
return z.NumOfWorkers
}
func (z *ZurgConfig) GetRefreshEverySecs() int {
if z.RefreshEverySecs == 0 {
return 60
}
return z.RefreshEverySecs
}
func (z *ZurgConfig) GetRepairEveryMins() int {
if z.RepairEveryMins == 0 {
return 60
}
return z.RepairEveryMins
}
func (z *ZurgConfig) GetDownloadsEveryMins() int {
if z.DownloadsEveryMins == 0 {
return 1440
}
return z.DownloadsEveryMins
}
func (z *ZurgConfig) GetDownloadsLimit() int {
if z.DownloadsLimit == 0 {
return 10000
}
return z.DownloadsLimit
}
func (z *ZurgConfig) GetDumpTorrentsEveryMins() int {
if z.DumpTorrentsEveryMins == 0 {
return 1440
}
return z.DumpTorrentsEveryMins
}
func (z *ZurgConfig) EnableRepair() bool {
return z.CanRepair
}
func (z *ZurgConfig) GetOnLibraryUpdate() string {
return z.OnLibraryUpdate
}
func (z *ZurgConfig) GetNetworkBufferSize() int {
if z.NetworkBufferSize == 0 {
return 32 * 1024 // 32kb
}
return z.NetworkBufferSize
}
func (z *ZurgConfig) EnableRetainFolderNameExtension() bool {
return z.RetainFolderNameExtension
}
func (z *ZurgConfig) EnableRetainRDTorrentName() bool {
return z.RetainRDTorrentName
}
func (z *ZurgConfig) ShouldIgnoreRenames() bool {
return !z.IgnoreRenames
}
func (z *ZurgConfig) ShouldServeFromRclone() bool {
return z.ServeFromRclone
}
func (z *ZurgConfig) ShouldForceIPv6() bool {
return z.ForceIPv6
}
func (z *ZurgConfig) GetRetriesUntilFailed() int {
if z.RetriesUntilFailed == 0 {
return 2
}
return z.RetriesUntilFailed
}
func (z *ZurgConfig) GetApiTimeoutSecs() int {
if z.ApiTimeoutSecs == 0 {
return 60
}
return z.ApiTimeoutSecs
}
func (z *ZurgConfig) GetDownloadTimeoutSecs() int {
if z.DownloadTimeoutSecs == 0 {
return 10
}
return z.DownloadTimeoutSecs
}
func (z *ZurgConfig) GetRateLimitSleepSecs() int {
if z.RateLimitSleepSecs == 0 {
return 4
}
return z.RateLimitSleepSecs
}
func (z *ZurgConfig) ShouldDeleteRarFiles() bool {
return z.DeleteRarFiles
}
func (z *ZurgConfig) GetPlayableExtensions() []string {
if len(z.PlayableExtensions) == 0 {
return []string{}
}
return z.PlayableExtensions
}
func (z *ZurgConfig) GetTorrentsCount() int {
if z.TorrentsCount == 0 {
return 100
}
return z.TorrentsCount
}