mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 04:57:37 +03:00
Return 404 when artwork is not available in /share/img
endpoint
This commit is contained in:
parent
128b626ec9
commit
d8e794317f
13 changed files with 75 additions and 90 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/navidrome/navidrome/core/artwork"
|
||||
"github.com/navidrome/navidrome/log"
|
||||
"github.com/navidrome/navidrome/model"
|
||||
"github.com/navidrome/navidrome/utils"
|
||||
|
@ -28,13 +29,17 @@ func (p *Router) handleImages(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
size := utils.ParamInt(r, "size", 0)
|
||||
imgReader, lastUpdate, err := p.artwork.Get(ctx, artId.String(), size)
|
||||
imgReader, lastUpdate, err := p.artwork.Get(ctx, artId, size)
|
||||
|
||||
switch {
|
||||
case errors.Is(err, context.Canceled):
|
||||
return
|
||||
case errors.Is(err, model.ErrNotFound):
|
||||
log.Error(r, "Couldn't find coverArt", "id", id, err)
|
||||
log.Warn(r, "Couldn't find coverArt", "id", id, err)
|
||||
http.Error(w, "Artwork not found", http.StatusNotFound)
|
||||
return
|
||||
case errors.Is(err, artwork.ErrUnavailable):
|
||||
log.Debug(r, "Item does not have artwork", "id", id, err)
|
||||
http.Error(w, "Artwork not found", http.StatusNotFound)
|
||||
return
|
||||
case err != nil:
|
||||
|
|
|
@ -59,7 +59,7 @@ func (api *Router) GetCoverArt(w http.ResponseWriter, r *http.Request) (*respons
|
|||
id := utils.ParamString(r, "id")
|
||||
size := utils.ParamInt(r, "size", 0)
|
||||
|
||||
imgReader, lastUpdate, err := api.artwork.Get(ctx, id, size)
|
||||
imgReader, lastUpdate, err := api.artwork.GetOrPlaceholder(ctx, id, size)
|
||||
w.Header().Set("cache-control", "public, max-age=315360000")
|
||||
w.Header().Set("last-modified", lastUpdate.Format(time.RFC1123))
|
||||
|
||||
|
@ -67,7 +67,7 @@ func (api *Router) GetCoverArt(w http.ResponseWriter, r *http.Request) (*respons
|
|||
case errors.Is(err, context.Canceled):
|
||||
return nil, nil
|
||||
case errors.Is(err, model.ErrNotFound):
|
||||
log.Error(r, "Couldn't find coverArt", "id", id, err)
|
||||
log.Warn(r, "Couldn't find coverArt", "id", id, err)
|
||||
return nil, newError(responses.ErrorDataNotFound, "Artwork not found")
|
||||
case err != nil:
|
||||
log.Error(r, "Error retrieving coverArt", "id", id, err)
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"net/http/httptest"
|
||||
"time"
|
||||
|
||||
"github.com/navidrome/navidrome/core/artwork"
|
||||
"github.com/navidrome/navidrome/log"
|
||||
"github.com/navidrome/navidrome/model"
|
||||
"github.com/navidrome/navidrome/tests"
|
||||
|
@ -105,13 +106,14 @@ var _ = Describe("MediaRetrievalController", func() {
|
|||
})
|
||||
|
||||
type fakeArtwork struct {
|
||||
artwork.Artwork
|
||||
data string
|
||||
err error
|
||||
recvId string
|
||||
recvSize int
|
||||
}
|
||||
|
||||
func (c *fakeArtwork) Get(_ context.Context, id string, size int) (io.ReadCloser, time.Time, error) {
|
||||
func (c *fakeArtwork) GetOrPlaceholder(_ context.Context, id string, size int) (io.ReadCloser, time.Time, error) {
|
||||
if c.err != nil {
|
||||
return nil, time.Time{}, c.err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue