Skip to content

🎧 Your Personal Streaming Service

Return cover from album even if client does not prefix the id with `al-`. Fixes #46

Deluan2d7998de5948
diff --git a/engine/cover.go b/engine/cover.go
index 622e5fd29..123df1a40 100644
--- a/engine/cover.go
+++ b/engine/cover.go
@@ -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
}
- 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
+ if al.CoverArtId == "" {
+ return "", model.ErrNotFound
}
+ return al.CoverArtPath, 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