Add new config option to limit number of active downloads
This commit is contained in:
parent
4b433304f6
commit
d1f92abb16
@ -15,6 +15,7 @@ type Server struct {
|
||||
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
|
||||
}
|
||||
|
||||
|
2
main.go
2
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
|
||||
|
@ -33,6 +33,10 @@
|
||||
<input type="text" id="config-server-downloadpath" placeholder="path" class="input-long" x-model="config.server.download_path" />
|
||||
<span class="pure-form-message">The path on the server to download files to.</span>
|
||||
|
||||
<label for="config-server-max-downloads">Maximum active downloads</label>
|
||||
<input type="text" id="config-server-max-downloads" placeholder="2" class="input-long" x-model.number="config.server.maximum_active_downloads_per_domain" />
|
||||
<span class="pure-form-message">How many downloads can be simultaneously active. Use '0' for no limit.</span>
|
||||
|
||||
<legend>UI</legend>
|
||||
|
||||
<p>Note that changes to the popup dimensions will require you to recreate your bookmarklet.</p>
|
||||
|
Loading…
x
Reference in New Issue
Block a user