mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 04:57:37 +03:00
Artwork reader for Artist
This commit is contained in:
parent
bf461473ef
commit
918fee3ea3
11 changed files with 99 additions and 24 deletions
|
@ -42,7 +42,10 @@ func (p *Router) routes() http.Handler {
|
|||
}
|
||||
|
||||
func (p *Router) handleImages(w http.ResponseWriter, r *http.Request) {
|
||||
_, claims, _ := jwtauth.FromContext(r.Context())
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
_, claims, _ := jwtauth.FromContext(ctx)
|
||||
id, ok := claims["id"].(string)
|
||||
if !ok {
|
||||
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||
|
@ -53,7 +56,8 @@ func (p *Router) handleImages(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
imgReader, lastUpdate, err := p.artwork.Get(r.Context(), id, int(size))
|
||||
|
||||
imgReader, lastUpdate, err := p.artwork.Get(ctx, id, int(size))
|
||||
w.Header().Set("cache-control", "public, max-age=315360000")
|
||||
w.Header().Set("last-modified", lastUpdate.Format(time.RFC1123))
|
||||
|
||||
|
@ -71,7 +75,10 @@ func (p *Router) handleImages(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
defer imgReader.Close()
|
||||
_, err = io.Copy(w, imgReader)
|
||||
cnt, err := io.Copy(w, imgReader)
|
||||
if err != nil {
|
||||
log.Warn(ctx, "Error sending image", "count", cnt, err)
|
||||
}
|
||||
}
|
||||
|
||||
func jwtVerifier(next http.Handler) http.Handler {
|
||||
|
|
|
@ -86,6 +86,7 @@ func toArtist(_ context.Context, a model.Artist) responses.Artist {
|
|||
Name: a.Name,
|
||||
AlbumCount: a.AlbumCount,
|
||||
UserRating: a.Rating,
|
||||
CoverArt: a.CoverArtID().String(),
|
||||
ArtistImageUrl: a.ArtistImageUrl(),
|
||||
}
|
||||
if a.Starred {
|
||||
|
@ -94,11 +95,12 @@ func toArtist(_ context.Context, a model.Artist) responses.Artist {
|
|||
return artist
|
||||
}
|
||||
|
||||
func toArtistID3(ctx context.Context, a model.Artist) responses.ArtistID3 {
|
||||
func toArtistID3(_ context.Context, a model.Artist) responses.ArtistID3 {
|
||||
artist := responses.ArtistID3{
|
||||
Id: a.ID,
|
||||
Name: a.Name,
|
||||
AlbumCount: a.AlbumCount,
|
||||
CoverArt: a.CoverArtID().String(),
|
||||
ArtistImageUrl: a.ArtistImageUrl(),
|
||||
UserRating: a.Rating,
|
||||
}
|
||||
|
|
|
@ -53,10 +53,13 @@ func (api *Router) getPlaceHolderAvatar(w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
|
||||
func (api *Router) GetCoverArt(w http.ResponseWriter, r *http.Request) (*responses.Subsonic, error) {
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
id := utils.ParamString(r, "id")
|
||||
size := utils.ParamInt(r, "size", 0)
|
||||
|
||||
imgReader, lastUpdate, err := api.artwork.Get(r.Context(), id, size)
|
||||
imgReader, lastUpdate, err := api.artwork.Get(ctx, id, size)
|
||||
w.Header().Set("cache-control", "public, max-age=315360000")
|
||||
w.Header().Set("last-modified", lastUpdate.Format(time.RFC1123))
|
||||
|
||||
|
@ -72,7 +75,10 @@ func (api *Router) GetCoverArt(w http.ResponseWriter, r *http.Request) (*respons
|
|||
}
|
||||
|
||||
defer imgReader.Close()
|
||||
_, err = io.Copy(w, imgReader)
|
||||
cnt, err := io.Copy(w, imgReader)
|
||||
if err != nil {
|
||||
log.Warn(ctx, "Error sending image", "count", cnt, err)
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -77,9 +77,9 @@ type Artist struct {
|
|||
AlbumCount int `xml:"albumCount,attr,omitempty" json:"albumCount,omitempty"`
|
||||
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
||||
UserRating int `xml:"userRating,attr,omitempty" json:"userRating,omitempty"`
|
||||
CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
|
||||
ArtistImageUrl string `xml:"artistImageUrl,attr,omitempty" json:"artistImageUrl,omitempty"`
|
||||
/* TODO:
|
||||
<xs:attribute name="coverArt" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="averageRating" type="sub:AverageRating" use="optional"/> <!-- Added in 1.13.0 -->
|
||||
*/
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue