60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package utils
|
|
|
|
import (
|
|
"errors"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
// Erreurs de validation pour les playlists
|
|
var (
|
|
ErrPlaylistTitleRequired = errors.New("playlist title is required")
|
|
ErrPlaylistTitleTooLong = errors.New("playlist title must be less than 200 characters")
|
|
ErrPlaylistDescTooLong = errors.New("playlist description must be less than 2000 characters")
|
|
ErrInvalidCoverURL = errors.New("invalid cover URL format")
|
|
ErrCoverURLTooLong = errors.New("cover URL must be less than 500 characters")
|
|
)
|
|
|
|
// ValidatePlaylistTitle valide le titre d'une playlist
|
|
// T0455: Validation du titre (requis, max 200 caractères)
|
|
func ValidatePlaylistTitle(title string) error {
|
|
if strings.TrimSpace(title) == "" {
|
|
return ErrPlaylistTitleRequired
|
|
}
|
|
if len(title) > 200 {
|
|
return ErrPlaylistTitleTooLong
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ValidatePlaylistDescription valide la description d'une playlist
|
|
// T0455: Validation de la description (max 2000 caractères)
|
|
func ValidatePlaylistDescription(description string) error {
|
|
if len(description) > 2000 {
|
|
return ErrPlaylistDescTooLong
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ValidateCoverURL valide l'URL de la couverture d'une playlist
|
|
// T0455: Validation de l'URL (format valide, http/https, max 500 caractères)
|
|
func ValidateCoverURL(coverURL string) error {
|
|
if coverURL == "" {
|
|
return nil // Optional field
|
|
}
|
|
|
|
parsedURL, err := url.Parse(coverURL)
|
|
if err != nil {
|
|
return ErrInvalidCoverURL
|
|
}
|
|
|
|
if parsedURL.Scheme != "http" && parsedURL.Scheme != "https" {
|
|
return ErrInvalidCoverURL
|
|
}
|
|
|
|
if len(coverURL) > 500 {
|
|
return ErrCoverURLTooLong
|
|
}
|
|
|
|
return nil
|
|
}
|