mirror of
https://github.com/navidrome/navidrome.git
synced 2025-05-02 19:31:45 +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,15 +32,21 @@ func NewCover(ds model.DataStore) Cover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *cover) getCoverPath(ctx context.Context, id string) (string, error) {
|
func (c *cover) getCoverPath(ctx context.Context, id string) (string, error) {
|
||||||
switch {
|
var found bool
|
||||||
case strings.HasPrefix(id, "al-"):
|
var err error
|
||||||
id = id[3:]
|
if found, err = c.ds.Album(ctx).Exists(id); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if found {
|
||||||
al, err := c.ds.Album(ctx).Get(id)
|
al, err := c.ds.Album(ctx).Get(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
if al.CoverArtId == "" {
|
||||||
|
return "", model.ErrNotFound
|
||||||
|
}
|
||||||
return al.CoverArtPath, nil
|
return al.CoverArtPath, nil
|
||||||
default:
|
}
|
||||||
mf, err := c.ds.MediaFile(ctx).Get(id)
|
mf, err := c.ds.MediaFile(ctx).Get(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -48,11 +54,11 @@ func (c *cover) getCoverPath(ctx context.Context, id string) (string, error) {
|
|||||||
if mf.HasCoverArt {
|
if mf.HasCoverArt {
|
||||||
return mf.Path, nil
|
return mf.Path, nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return "", model.ErrNotFound
|
return "", model.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cover) Get(ctx context.Context, id string, size int, out io.Writer) error {
|
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)
|
path, err := c.getCoverPath(ctx, id)
|
||||||
if err != nil && err != model.ErrNotFound {
|
if err != nil && err != model.ErrNotFound {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user