Fix tests and lint errors, plus a bit of refactor

This commit is contained in:
Deluan
2023-01-22 12:25:35 -05:00
parent 72a12e344e
commit 94cc2b2ac5
14 changed files with 114 additions and 98 deletions
+4 -3
View File
@@ -10,6 +10,7 @@ import (
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/server/public"
"github.com/navidrome/navidrome/server/subsonic/filter"
"github.com/navidrome/navidrome/server/subsonic/responses"
"github.com/navidrome/navidrome/utils"
@@ -256,9 +257,9 @@ func (api *Router) GetArtistInfo(r *http.Request) (*responses.Subsonic, error) {
response := newResponse()
response.ArtistInfo = &responses.ArtistInfo{}
response.ArtistInfo.Biography = artist.Biography
response.ArtistInfo.SmallImageUrl = publicImageURL(r, artist.CoverArtID(), 160)
response.ArtistInfo.MediumImageUrl = publicImageURL(r, artist.CoverArtID(), 320)
response.ArtistInfo.LargeImageUrl = publicImageURL(r, artist.CoverArtID(), 0)
response.ArtistInfo.SmallImageUrl = public.ImageURL(r, artist.CoverArtID(), 160)
response.ArtistInfo.MediumImageUrl = public.ImageURL(r, artist.CoverArtID(), 320)
response.ArtistInfo.LargeImageUrl = public.ImageURL(r, artist.CoverArtID(), 0)
response.ArtistInfo.LastFmUrl = artist.ExternalUrl
response.ArtistInfo.MusicBrainzID = artist.MbzArtistID
for _, s := range artist.SimilarArtists {
+2 -16
View File
@@ -5,15 +5,11 @@ import (
"fmt"
"mime"
"net/http"
"net/url"
"path/filepath"
"strconv"
"strings"
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/model/request"
"github.com/navidrome/navidrome/server"
"github.com/navidrome/navidrome/server/public"
"github.com/navidrome/navidrome/server/subsonic/responses"
"github.com/navidrome/navidrome/utils"
@@ -92,7 +88,7 @@ func toArtist(r *http.Request, a model.Artist) responses.Artist {
AlbumCount: a.AlbumCount,
UserRating: a.Rating,
CoverArt: a.CoverArtID().String(),
ArtistImageUrl: publicImageURL(r, a.CoverArtID(), 0),
ArtistImageUrl: public.ImageURL(r, a.CoverArtID(), 0),
}
if a.Starred {
artist.Starred = &a.StarredAt
@@ -106,7 +102,7 @@ func toArtistID3(r *http.Request, a model.Artist) responses.ArtistID3 {
Name: a.Name,
AlbumCount: a.AlbumCount,
CoverArt: a.CoverArtID().String(),
ArtistImageUrl: publicImageURL(r, a.CoverArtID(), 0),
ArtistImageUrl: public.ImageURL(r, a.CoverArtID(), 0),
UserRating: a.Rating,
}
if a.Starred {
@@ -115,16 +111,6 @@ func toArtistID3(r *http.Request, a model.Artist) responses.ArtistID3 {
return artist
}
func publicImageURL(r *http.Request, artID model.ArtworkID, size int) string {
link := public.EncodeArtworkID(artID)
path := filepath.Join(consts.URLPathPublicImages, link)
params := url.Values{}
if size > 0 {
params.Add("size", strconv.Itoa(size))
}
return server.AbsoluteURL(r, path, params)
}
func toGenres(genres model.Genres) *responses.Genres {
response := make([]responses.Genre, len(genres))
for i, g := range genres {
+2 -1
View File
@@ -12,6 +12,7 @@ import (
"github.com/deluan/sanitize"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/server/public"
"github.com/navidrome/navidrome/server/subsonic/responses"
"github.com/navidrome/navidrome/utils"
)
@@ -112,7 +113,7 @@ func (api *Router) Search2(r *http.Request) (*responses.Subsonic, error) {
AlbumCount: artist.AlbumCount,
UserRating: artist.Rating,
CoverArt: artist.CoverArtID().String(),
ArtistImageUrl: publicImageURL(r, artist.CoverArtID(), 0),
ArtistImageUrl: public.ImageURL(r, artist.CoverArtID(), 0),
}
if artist.Starred {
searchResult2.Artist[i].Starred = &as[i].StarredAt