mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-15 03:30:39 +03:00
Handle empty cover art ID in subsonic API
This commit is contained in:
parent
0da27e8a3f
commit
abd3274250
@ -41,9 +41,13 @@ type artwork struct {
|
||||
}
|
||||
|
||||
func (a *artwork) Get(ctx context.Context, id string, size int) (io.ReadCloser, error) {
|
||||
artID, err := model.ParseArtworkID(id)
|
||||
if err != nil {
|
||||
return nil, errors.New("invalid ID")
|
||||
var artID model.ArtworkID
|
||||
var err error
|
||||
if id != "" {
|
||||
artID, err = model.ParseArtworkID(id)
|
||||
if err != nil {
|
||||
return nil, errors.New("invalid ID")
|
||||
}
|
||||
}
|
||||
|
||||
key := &artworkKey{a: a, artID: artID, size: size}
|
||||
|
@ -41,6 +41,14 @@ var _ = Describe("Artwork", func() {
|
||||
aw = NewArtwork(ds, cache).(*artwork)
|
||||
})
|
||||
|
||||
Context("Empty ID", func() {
|
||||
It("returns placeholder if album is not in the DB", func() {
|
||||
_, path, err := aw.get(context.Background(), model.ArtworkID{}, 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(path).To(Equal(consts.PlaceholderAlbumArt))
|
||||
})
|
||||
})
|
||||
|
||||
Context("Albums", func() {
|
||||
Context("ID not found", func() {
|
||||
It("returns placeholder if album is not in the DB", func() {
|
||||
|
@ -51,7 +51,7 @@ func (api *Router) getPlaceHolderAvatar(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
func (api *Router) GetCoverArt(w http.ResponseWriter, r *http.Request) (*responses.Subsonic, error) {
|
||||
id := utils.ParamStringDefault(r, "id", "non-existent")
|
||||
id := utils.ParamString(r, "id")
|
||||
size := utils.ParamInt(r, "size", 0)
|
||||
|
||||
w.Header().Set("cache-control", "public, max-age=315360000")
|
||||
|
Loading…
x
Reference in New Issue
Block a user