Files
zurg/internal/config/types.go
2023-11-28 01:11:55 +01:00

147 lines
3.6 KiB
Go

package config
import "math/rand"
type ConfigInterface interface {
GetVersion() string
GetToken() string
GetNumOfWorkers() int
GetRefreshEverySeconds() int
EnableRepair() bool
GetHost() string
GetPort() string
GetDirectories() []string
MeetsConditions(directory, torrentName string, torrentIDs, fileNames []string) bool
GetOnLibraryUpdate() string
GetNetworkBufferSize() int
GetMountPoint() string
EnableRetainFolderNameExtension() bool
EnableRetainRDTorrentName() bool
GetRandomPreferredHost() string
ShouldServeFromRclone() bool
ShouldForceIPv6() bool
GetUnrestrictWorkers() int
GetReleaseUnrestrictAfterMs() int
GetRateLimitSleepSeconds() int
}
type ZurgConfig struct {
Version string `yaml:"zurg"`
Token string `yaml:"token"`
Host string `yaml:"host"`
Port string `yaml:"port"`
NumOfWorkers int `yaml:"concurrent_workers"`
UnrestrictWorkers int `yaml:"unrestrict_workers"`
ReleaseUnrestrictAfterMs int `yaml:"release_unrestrict_after_ms"`
RateLimitSleepSeconds int `yaml:"rate_limit_sleep_secs"`
RefreshEverySeconds int `yaml:"check_for_changes_every_secs"`
CanRepair bool `yaml:"enable_repair"`
OnLibraryUpdate string `yaml:"on_library_update"`
NetworkBufferSize int `yaml:"network_buffer_size"`
MountPoint string `yaml:"mount_point"`
RetainFolderNameExtension bool `yaml:"retain_folder_name_extension"`
RetainRDTorrentName bool `yaml:"retain_rd_torrent_name"`
PreferredHosts []string `yaml:"preferred_hosts"`
ServeFromRclone bool `yaml:"serve_from_rclone"`
ForceIPv6 bool `yaml:"force_ipv6"`
}
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 z.Port == "" {
return "9999"
}
return z.Port
}
func (z *ZurgConfig) GetNumOfWorkers() int {
if z.NumOfWorkers == 0 {
return 50
}
return z.NumOfWorkers
}
func (z *ZurgConfig) GetRefreshEverySeconds() int {
if z.RefreshEverySeconds == 0 {
return 60
}
return z.RefreshEverySeconds
}
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 64 * 1024 // 64kb
}
return z.NetworkBufferSize
}
func (z *ZurgConfig) GetMountPoint() string {
if z.MountPoint == "" {
return "/app/mnt"
}
return z.MountPoint
}
func (z *ZurgConfig) EnableRetainFolderNameExtension() bool {
return z.RetainFolderNameExtension
}
func (z *ZurgConfig) EnableRetainRDTorrentName() bool {
return z.RetainRDTorrentName
}
func (z *ZurgConfig) GetRandomPreferredHost() string {
if len(z.PreferredHosts) == 0 {
return ""
}
randomIndex := rand.Intn(len(z.PreferredHosts))
return z.PreferredHosts[randomIndex]
}
func (z *ZurgConfig) ShouldServeFromRclone() bool {
return z.ServeFromRclone
}
func (z *ZurgConfig) ShouldForceIPv6() bool {
return z.ForceIPv6
}
func (z *ZurgConfig) GetUnrestrictWorkers() int {
if z.UnrestrictWorkers == 0 {
return 20
}
return z.UnrestrictWorkers
}
func (z *ZurgConfig) GetReleaseUnrestrictAfterMs() int {
if z.ReleaseUnrestrictAfterMs == 0 {
return 100
}
return z.ReleaseUnrestrictAfterMs
}
func (z *ZurgConfig) GetRateLimitSleepSeconds() int {
if z.RateLimitSleepSeconds == 0 {
return 4
}
return z.RateLimitSleepSeconds
}