refactor: validate limit only for artist downloads

This commit is contained in:
Mathis Maquenne
2026-08-05 12:42:51 +02:00
parent e90a56ec53
commit 5bb1448650
3 changed files with 28 additions and 21 deletions
+10 -6
View File
@@ -3,6 +3,8 @@ package download
import (
"fmt"
"time"
"github.com/mathismqn/godeez/internal/deezer"
)
var validQualities = map[string]bool{
@@ -20,18 +22,20 @@ type Options struct {
Strict bool
}
func (o *Options) Validate() error {
func (o *Options) Validate(kind deezer.Kind) error {
if !validQualities[o.Quality] {
return fmt.Errorf("invalid quality option: %s", o.Quality)
}
if o.Timeout <= 0 {
return fmt.Errorf("timeout must be a positive duration")
}
if o.Limit <= 0 {
return fmt.Errorf("limit must be a positive integer")
}
if o.Limit > 100 {
return fmt.Errorf("limit must not exceed 100")
if kind == deezer.KindArtist {
if o.Limit <= 0 {
return fmt.Errorf("limit must be a positive integer")
}
if o.Limit > 100 {
return fmt.Errorf("limit must not exceed 100")
}
}
return nil