Initial DDC release
This commit is contained in:
commit
434f6441da
57 files changed
+4606
No files matched your search
@@ -0,0 +1,41 @@
|
||||
package preferences
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const (
|
||||
gigabyte = int64(1) << 30
|
||||
maxConcurrentLimit = 10
|
||||
maxReservedGigabytes = 100000
|
||||
)
|
||||
|
||||
var ErrInvalid = errors.New("invalid settings")
|
||||
|
||||
type Preferences struct {
|
||||
MaxConcurrentDownloads int `json:"maxConcurrentDownloads"`
|
||||
MinFreeGB int `json:"minFreeGB"`
|
||||
AllowedPorts []uint16 `json:"allowedPorts"`
|
||||
AutoExtract bool `json:"autoExtract"`
|
||||
CleanupAfterMove bool `json:"cleanupAfterMove"`
|
||||
}
|
||||
|
||||
func (preferences Preferences) MinFreeBytes() int64 {
|
||||
return int64(preferences.MinFreeGB) * gigabyte
|
||||
}
|
||||
|
||||
func (preferences Preferences) Validate() error {
|
||||
if preferences.MaxConcurrentDownloads < 1 || preferences.MaxConcurrentDownloads > maxConcurrentLimit {
|
||||
return fmt.Errorf("%w: parallel downloads must be between 1 and %d", ErrInvalid, maxConcurrentLimit)
|
||||
}
|
||||
if preferences.MinFreeGB < 0 || preferences.MinFreeGB > maxReservedGigabytes {
|
||||
return fmt.Errorf("%w: free space to keep must be between 0 and %d GB", ErrInvalid, maxReservedGigabytes)
|
||||
}
|
||||
for _, port := range preferences.AllowedPorts {
|
||||
if port == 0 {
|
||||
return fmt.Errorf("%w: port 0 is not allowed", ErrInvalid)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user