mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
Parse correctly playlist CoverArt ids
This commit is contained in:
parent
8f3387a894
commit
501386b11f
4 changed files with 24 additions and 9 deletions
|
@ -4,6 +4,8 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
type Kind struct{ prefix string }
|
||||
|
@ -11,8 +13,15 @@ type Kind struct{ prefix string }
|
|||
var (
|
||||
KindMediaFileArtwork = Kind{"mf"}
|
||||
KindAlbumArtwork = Kind{"al"}
|
||||
KindPlaylistArtwork = Kind{"pl"}
|
||||
)
|
||||
|
||||
var artworkKindList = []string{
|
||||
KindAlbumArtwork.prefix,
|
||||
KindMediaFileArtwork.prefix,
|
||||
KindPlaylistArtwork.prefix,
|
||||
}
|
||||
|
||||
type ArtworkID struct {
|
||||
Kind Kind
|
||||
ID string
|
||||
|
@ -26,11 +35,11 @@ func (id ArtworkID) String() string {
|
|||
}
|
||||
|
||||
func ParseArtworkID(id string) (ArtworkID, error) {
|
||||
parts := strings.Split(id, "-")
|
||||
parts := strings.SplitN(id, "-", 2)
|
||||
if len(parts) != 2 {
|
||||
return ArtworkID{}, errors.New("invalid artwork id")
|
||||
}
|
||||
if parts[0] != KindAlbumArtwork.prefix && parts[0] != KindMediaFileArtwork.prefix {
|
||||
if !slices.Contains(artworkKindList, parts[0]) {
|
||||
return ArtworkID{}, errors.New("invalid artwork kind")
|
||||
}
|
||||
return ArtworkID{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue