From d1f92abb16ac999d12a823960329cf3497648dda Mon Sep 17 00:00:00 2001 From: Justin Hawkins Date: Sun, 21 Nov 2021 13:25:55 +1030 Subject: [PATCH] Add new config option to limit number of active downloads --- config/config.go | 30 ++++++++++++++++++++++++++---- main.go | 2 +- web/config.html | 4 ++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index a327b13..e8c18fe 100644 --- a/config/config.go +++ b/config/config.go @@ -12,9 +12,10 @@ import ( ) type Server struct { - Port int `yaml:"port" json:"port"` - Address string `yaml:"address" json:"address"` - DownloadPath string `yaml:"download_path" json:"download_path"` + Port int `yaml:"port" json:"port"` + Address string `yaml:"address" json:"address"` + DownloadPath string `yaml:"download_path" json:"download_path"` + MaximumActiveDownloadsPerDomain int `yaml:"maximum_active_downloads_per_domain" json:"maximum_active_downloads_per_domain"` } type DownloadProfile struct { @@ -60,7 +61,9 @@ func DefaultConfig() *Config { defaultConfig.UI.PopupWidth = 500 defaultConfig.UI.PopupHeight = 500 - defaultConfig.ConfigVersion = 1 + defaultConfig.Server.MaximumActiveDownloadsPerDomain = 2 + + defaultConfig.ConfigVersion = 2 return &defaultConfig } @@ -104,6 +107,10 @@ func (c *Config) UpdateFromJSON(j []byte) error { return fmt.Errorf("path '%s' is not a directory", newConfig.Server.DownloadPath) } + if newConfig.Server.MaximumActiveDownloadsPerDomain < 0 { + return fmt.Errorf("maximum active downloads can not be < 0") + } + // check profile name uniqueness for i, p1 := range newConfig.DownloadProfiles { for j, p2 := range newConfig.DownloadProfiles { @@ -189,6 +196,21 @@ func LoadConfig() (*Config, error) { log.Printf("Could not parse YAML config '%s': %v", path, err) return nil, err } + + // do migrations + configMigrated := false + if c.ConfigVersion == 1 { + c.Server.MaximumActiveDownloadsPerDomain = 2 + c.ConfigVersion = 2 + configMigrated = true + log.Print("migrated config from version 1 => 2") + } + + if configMigrated { + log.Print("Writing new config after version migration") + c.WriteConfig() + } + return &c, nil } diff --git a/main.go b/main.go index c3046c4..b3a3748 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,7 @@ var downloads []*download.Download var downloadId = 0 var conf *config.Config -var versionInfo = version.Info{CurrentVersion: "v0.5.2"} +var versionInfo = version.Info{CurrentVersion: "v0.5.3"} //go:embed web var webFS embed.FS diff --git a/web/config.html b/web/config.html index 2fb3558..855bfe4 100644 --- a/web/config.html +++ b/web/config.html @@ -33,6 +33,10 @@ The path on the server to download files to. + + + How many downloads can be simultaneously active. Use '0' for no limit. + UI

Note that changes to the popup dimensions will require you to recreate your bookmarklet.