Skip to content

Commit

Permalink
Add PollBlackhole option and update config version updating
Browse files Browse the repository at this point in the history
  • Loading branch information
JackDallas committed Jun 30, 2022
1 parent d9bd141 commit b03a37b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
63 changes: 39 additions & 24 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,51 @@ func loadConfigFromDisk(altConfigLocation string) (Config, error) {
var config Config

log.Trace("Trying to load config from disk")

configLocation := path.Join(altConfigLocation, "config.yaml")

log.Tracef("Reading config from %s", configLocation)

file, err := ioutil.ReadFile(configLocation)

if err != nil {
log.Trace("Failed to find config file")
return config, ErrFailedToFindConfigFile
}

log.Trace("Attempting to unmarshal config")
log.Trace("Loading to interface")
var configInterface map[interface{}]interface{}
err = yaml.Unmarshal(file, &configInterface)
if err != nil {
log.Errorf("Failed to unmarshal config file: %+v", err)
return config, ErrInvalidConfigFile
}

log.Trace("Unmarshalling to struct")
err = yaml.Unmarshal(file, &config)
if err != nil {
log.Trace("Failed to unmarshal config")
log.Errorf("Failed to unmarshal config file: %+v", err)
return config, ErrInvalidConfigFile
}

log.Trace("Config loaded, running version update")
config, updated := versionUpdateConfig(config)
log.Trace("Checking for missing config fields")
updated := false

if configInterface["PollBlackholeDirectory"] == nil {
log.Info("PollBlackholeDirectory not set, setting to false")
config.PollBlackholeDirectory = false
updated = true
}

if configInterface["SimultaneousDownloads"] == nil {
log.Info("SimultaneousDownloads not set, setting to 5")
config.SimultaneousDownloads = 5
updated = true
}

if configInterface["PollBlackholeIntervalMinutes"] == nil {
log.Info("PollBlackholeIntervalMinutes not set, setting to 10")
config.PollBlackholeIntervalMinutes = 10
updated = true
}

config.altConfigLocation = altConfigLocation

Expand All @@ -123,31 +147,22 @@ func loadConfigFromDisk(altConfigLocation string) (Config, error) {
return config, nil
}

func versionUpdateConfig(config Config) (Config, bool) {
updated := false
// 1.1.3
if config.SimultaneousDownloads == 0 {
config.SimultaneousDownloads = 5
updated = true
}

return config, updated
}

func defaultConfig() Config {
return Config{
PremiumizemeAPIKey: "xxxxxxxxx",
Arrs: []ArrConfig{
{Name: "Sonarr", URL: "http://localhost:8989", APIKey: "xxxxxxxxx", Type: Sonarr},
{Name: "Radarr", URL: "http://localhost:7878", APIKey: "xxxxxxxxx", Type: Radarr},
},
BlackholeDirectory: "",
DownloadsDirectory: "",
UnzipDirectory: "",
BindIP: "0.0.0.0",
BindPort: "8182",
WebRoot: "",
SimultaneousDownloads: 5,
BlackholeDirectory: "",
PollBlackholeDirectory: false,
PollBlackholeIntervalMinutes: 10,
DownloadsDirectory: "",
UnzipDirectory: "",
BindIP: "0.0.0.0",
BindPort: "8182",
WebRoot: "",
SimultaneousDownloads: 5,
}
}

Expand Down
5 changes: 4 additions & 1 deletion internal/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ type Config struct {

Arrs []ArrConfig `yaml:"Arrs"`

BlackholeDirectory string `yaml:"BlackholeDirectory"`
BlackholeDirectory string `yaml:"BlackholeDirectory"`
PollBlackholeDirectory bool `yaml:"PollBlackholeDirectory"`
PollBlackholeIntervalMinutes int `yaml:"PollBlackholeIntervalMinutes"`

DownloadsDirectory string `yaml:"DownloadsDirectory"`

UnzipDirectory string `yaml:"UnzipDirectory"`
Expand Down

0 comments on commit b03a37b

Please sign in to comment.