mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-28 09:22:18 +03:00
Return cover from album even if client does not prefix the id with al-
. Fixes #46
This commit is contained in:
parent
40638688b2
commit
2d7998de59
@ -32,27 +32,33 @@ func NewCover(ds model.DataStore) Cover {
|
||||
}
|
||||
|
||||
func (c *cover) getCoverPath(ctx context.Context, id string) (string, error) {
|
||||
switch {
|
||||
case strings.HasPrefix(id, "al-"):
|
||||
id = id[3:]
|
||||
var found bool
|
||||
var err error
|
||||
if found, err = c.ds.Album(ctx).Exists(id); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if found {
|
||||
al, err := c.ds.Album(ctx).Get(id)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if al.CoverArtId == "" {
|
||||
return "", model.ErrNotFound
|
||||
}
|
||||
return al.CoverArtPath, nil
|
||||
default:
|
||||
mf, err := c.ds.MediaFile(ctx).Get(id)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if mf.HasCoverArt {
|
||||
return mf.Path, nil
|
||||
}
|
||||
}
|
||||
mf, err := c.ds.MediaFile(ctx).Get(id)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if mf.HasCoverArt {
|
||||
return mf.Path, nil
|
||||
}
|
||||
return "", model.ErrNotFound
|
||||
}
|
||||
|
||||
func (c *cover) Get(ctx context.Context, id string, size int, out io.Writer) error {
|
||||
id = strings.TrimPrefix(id, "al-")
|
||||
path, err := c.getCoverPath(ctx, id)
|
||||
if err != nil && err != model.ErrNotFound {
|
||||
return err
|
||||
|
Loading…
x
Reference in New Issue
Block a user