mirror of
https://github.com/navidrome/navidrome.git
synced 2026-05-03 06:51:16 +00:00
Merge branch 'master' into subsonic-folder
This commit is contained in:
commit
61bb1a610c
@ -1,116 +0,0 @@
|
||||
package spotify
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/navidrome/navidrome/log"
|
||||
)
|
||||
|
||||
const apiBaseUrl = "https://api.spotify.com/v1/"
|
||||
|
||||
var (
|
||||
ErrNotFound = errors.New("spotify: not found")
|
||||
)
|
||||
|
||||
type httpDoer interface {
|
||||
Do(req *http.Request) (*http.Response, error)
|
||||
}
|
||||
|
||||
func newClient(id, secret string, hc httpDoer) *client {
|
||||
return &client{id, secret, hc}
|
||||
}
|
||||
|
||||
type client struct {
|
||||
id string
|
||||
secret string
|
||||
hc httpDoer
|
||||
}
|
||||
|
||||
func (c *client) searchArtists(ctx context.Context, name string, limit int) ([]Artist, error) {
|
||||
token, err := c.authorize(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
params := url.Values{}
|
||||
params.Add("type", "artist")
|
||||
params.Add("q", name)
|
||||
params.Add("offset", "0")
|
||||
params.Add("limit", strconv.Itoa(limit))
|
||||
req, _ := http.NewRequestWithContext(ctx, "GET", apiBaseUrl+"search", nil)
|
||||
req.URL.RawQuery = params.Encode()
|
||||
req.Header.Add("Authorization", "Bearer "+token)
|
||||
|
||||
var results SearchResults
|
||||
err = c.makeRequest(req, &results)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(results.Artists.Items) == 0 {
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
return results.Artists.Items, err
|
||||
}
|
||||
|
||||
func (c *client) authorize(ctx context.Context) (string, error) {
|
||||
payload := url.Values{}
|
||||
payload.Add("grant_type", "client_credentials")
|
||||
|
||||
encodePayload := payload.Encode()
|
||||
req, _ := http.NewRequestWithContext(ctx, "POST", "https://accounts.spotify.com/api/token", strings.NewReader(encodePayload))
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
req.Header.Add("Content-Length", strconv.Itoa(len(encodePayload)))
|
||||
auth := c.id + ":" + c.secret
|
||||
req.Header.Add("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(auth)))
|
||||
|
||||
response := map[string]any{}
|
||||
err := c.makeRequest(req, &response)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if v, ok := response["access_token"]; ok {
|
||||
return v.(string), nil
|
||||
}
|
||||
log.Error(ctx, "Invalid spotify response", "resp", response)
|
||||
return "", errors.New("invalid response")
|
||||
}
|
||||
|
||||
func (c *client) makeRequest(req *http.Request, response any) error {
|
||||
log.Trace(req.Context(), fmt.Sprintf("Sending Spotify %s request", req.Method), "url", req.URL)
|
||||
resp, err := c.hc.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return c.parseError(data)
|
||||
}
|
||||
|
||||
return json.Unmarshal(data, response)
|
||||
}
|
||||
|
||||
func (c *client) parseError(data []byte) error {
|
||||
var e Error
|
||||
err := json.Unmarshal(data, &e)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("spotify error(%s): %s", e.Code, e.Message)
|
||||
}
|
||||
@ -1,131 +0,0 @@
|
||||
package spotify
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("client", func() {
|
||||
var httpClient *fakeHttpClient
|
||||
var client *client
|
||||
|
||||
BeforeEach(func() {
|
||||
httpClient = &fakeHttpClient{}
|
||||
client = newClient("SPOTIFY_ID", "SPOTIFY_SECRET", httpClient)
|
||||
})
|
||||
|
||||
Describe("ArtistImages", func() {
|
||||
It("returns artist images from a successful request", func() {
|
||||
f, _ := os.Open("tests/fixtures/spotify.search.artist.json")
|
||||
httpClient.mock("https://api.spotify.com/v1/search", http.Response{Body: f, StatusCode: 200})
|
||||
httpClient.mock("https://accounts.spotify.com/api/token", http.Response{
|
||||
StatusCode: 200,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{"access_token": "NEW_ACCESS_TOKEN","token_type": "Bearer","expires_in": 3600}`)),
|
||||
})
|
||||
|
||||
artists, err := client.searchArtists(context.TODO(), "U2", 10)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(artists).To(HaveLen(20))
|
||||
Expect(artists[0].Popularity).To(Equal(82))
|
||||
|
||||
images := artists[0].Images
|
||||
Expect(images).To(HaveLen(3))
|
||||
Expect(images[0].Width).To(Equal(640))
|
||||
Expect(images[1].Width).To(Equal(320))
|
||||
Expect(images[2].Width).To(Equal(160))
|
||||
})
|
||||
|
||||
It("fails if artist was not found", func() {
|
||||
httpClient.mock("https://api.spotify.com/v1/search", http.Response{
|
||||
StatusCode: 200,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{
|
||||
"artists" : {
|
||||
"href" : "https://api.spotify.com/v1/search?query=dasdasdas%2Cdna&type=artist&offset=0&limit=20",
|
||||
"items" : [ ], "limit" : 20, "next" : null, "offset" : 0, "previous" : null, "total" : 0
|
||||
}}`)),
|
||||
})
|
||||
httpClient.mock("https://accounts.spotify.com/api/token", http.Response{
|
||||
StatusCode: 200,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{"access_token": "NEW_ACCESS_TOKEN","token_type": "Bearer","expires_in": 3600}`)),
|
||||
})
|
||||
|
||||
_, err := client.searchArtists(context.TODO(), "U2", 10)
|
||||
Expect(err).To(MatchError(ErrNotFound))
|
||||
})
|
||||
|
||||
It("fails if not able to authorize", func() {
|
||||
f, _ := os.Open("tests/fixtures/spotify.search.artist.json")
|
||||
httpClient.mock("https://api.spotify.com/v1/search", http.Response{Body: f, StatusCode: 200})
|
||||
httpClient.mock("https://accounts.spotify.com/api/token", http.Response{
|
||||
StatusCode: 400,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{"error":"invalid_client","error_description":"Invalid client"}`)),
|
||||
})
|
||||
|
||||
_, err := client.searchArtists(context.TODO(), "U2", 10)
|
||||
Expect(err).To(MatchError("spotify error(invalid_client): Invalid client"))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("authorize", func() {
|
||||
It("returns an access_token on successful authorization", func() {
|
||||
httpClient.mock("https://accounts.spotify.com/api/token", http.Response{
|
||||
StatusCode: 200,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{"access_token": "NEW_ACCESS_TOKEN","token_type": "Bearer","expires_in": 3600}`)),
|
||||
})
|
||||
|
||||
token, err := client.authorize(context.TODO())
|
||||
Expect(err).To(BeNil())
|
||||
Expect(token).To(Equal("NEW_ACCESS_TOKEN"))
|
||||
auth := httpClient.lastRequest.Header.Get("Authorization")
|
||||
Expect(auth).To(Equal("Basic U1BPVElGWV9JRDpTUE9USUZZX1NFQ1JFVA=="))
|
||||
})
|
||||
|
||||
It("fails on unsuccessful authorization", func() {
|
||||
httpClient.mock("https://accounts.spotify.com/api/token", http.Response{
|
||||
StatusCode: 400,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{"error":"invalid_client","error_description":"Invalid client"}`)),
|
||||
})
|
||||
|
||||
_, err := client.authorize(context.TODO())
|
||||
Expect(err).To(MatchError("spotify error(invalid_client): Invalid client"))
|
||||
})
|
||||
|
||||
It("fails on invalid JSON response", func() {
|
||||
httpClient.mock("https://accounts.spotify.com/api/token", http.Response{
|
||||
StatusCode: 200,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{NOT_VALID}`)),
|
||||
})
|
||||
|
||||
_, err := client.authorize(context.TODO())
|
||||
Expect(err).To(MatchError("invalid character 'N' looking for beginning of object key string"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
type fakeHttpClient struct {
|
||||
responses map[string]*http.Response
|
||||
lastRequest *http.Request
|
||||
}
|
||||
|
||||
func (c *fakeHttpClient) mock(url string, response http.Response) {
|
||||
if c.responses == nil {
|
||||
c.responses = make(map[string]*http.Response)
|
||||
}
|
||||
c.responses[url] = &response
|
||||
}
|
||||
|
||||
func (c *fakeHttpClient) Do(req *http.Request) (*http.Response, error) {
|
||||
c.lastRequest = req
|
||||
u := req.URL
|
||||
u.RawQuery = ""
|
||||
if resp, ok := c.responses[u.String()]; ok {
|
||||
return resp, nil
|
||||
}
|
||||
panic("URL not mocked: " + u.String())
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
package spotify
|
||||
|
||||
type SearchResults struct {
|
||||
Artists ArtistsResult `json:"artists"`
|
||||
}
|
||||
|
||||
type ArtistsResult struct {
|
||||
HRef string `json:"href"`
|
||||
Items []Artist `json:"items"`
|
||||
}
|
||||
|
||||
type Artist struct {
|
||||
Genres []string `json:"genres"`
|
||||
HRef string `json:"href"`
|
||||
ID string `json:"id"`
|
||||
Popularity int `json:"popularity"`
|
||||
Images []Image `json:"images"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type Image struct {
|
||||
URL string `json:"url"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
}
|
||||
|
||||
type Error struct {
|
||||
Code string `json:"error"`
|
||||
Message string `json:"error_description"`
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
package spotify
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Responses", func() {
|
||||
Describe("Search type=artist", func() {
|
||||
It("parses the artist search result correctly ", func() {
|
||||
var resp SearchResults
|
||||
body, _ := os.ReadFile("tests/fixtures/spotify.search.artist.json")
|
||||
err := json.Unmarshal(body, &resp)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
Expect(resp.Artists.Items).To(HaveLen(20))
|
||||
u2 := resp.Artists.Items[0]
|
||||
Expect(u2.Name).To(Equal("U2"))
|
||||
Expect(u2.Genres).To(ContainElements("irish rock", "permanent wave", "rock"))
|
||||
Expect(u2.ID).To(Equal("51Blml2LZPmy7TTiAg47vQ"))
|
||||
Expect(u2.HRef).To(Equal("https://api.spotify.com/v1/artists/51Blml2LZPmy7TTiAg47vQ"))
|
||||
Expect(u2.Images[0].URL).To(Equal("https://i.scdn.co/image/e22d5c0c8139b8439440a69854ed66efae91112d"))
|
||||
Expect(u2.Images[0].Width).To(Equal(640))
|
||||
Expect(u2.Images[0].Height).To(Equal(640))
|
||||
Expect(u2.Images[1].URL).To(Equal("https://i.scdn.co/image/40d6c5c14355cfc127b70da221233315497ec91d"))
|
||||
Expect(u2.Images[1].Width).To(Equal(320))
|
||||
Expect(u2.Images[1].Height).To(Equal(320))
|
||||
Expect(u2.Images[2].URL).To(Equal("https://i.scdn.co/image/7293d6752ae8a64e34adee5086858e408185b534"))
|
||||
Expect(u2.Images[2].Width).To(Equal(160))
|
||||
Expect(u2.Images[2].Height).To(Equal(160))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("Error", func() {
|
||||
It("parses the error response correctly", func() {
|
||||
var errorResp Error
|
||||
body := []byte(`{"error":"invalid_client","error_description":"Invalid client"}`)
|
||||
err := json.Unmarshal(body, &errorResp)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
Expect(errorResp.Code).To(Equal("invalid_client"))
|
||||
Expect(errorResp.Message).To(Equal("Invalid client"))
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -1,96 +0,0 @@
|
||||
package spotify
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/navidrome/navidrome/conf"
|
||||
"github.com/navidrome/navidrome/consts"
|
||||
"github.com/navidrome/navidrome/core/agents"
|
||||
"github.com/navidrome/navidrome/log"
|
||||
"github.com/navidrome/navidrome/model"
|
||||
"github.com/navidrome/navidrome/utils/cache"
|
||||
"github.com/xrash/smetrics"
|
||||
)
|
||||
|
||||
const spotifyAgentName = "spotify"
|
||||
|
||||
type spotifyAgent struct {
|
||||
ds model.DataStore
|
||||
id string
|
||||
secret string
|
||||
client *client
|
||||
}
|
||||
|
||||
func spotifyConstructor(ds model.DataStore) agents.Interface {
|
||||
if conf.Server.Spotify.ID == "" || conf.Server.Spotify.Secret == "" {
|
||||
return nil
|
||||
}
|
||||
l := &spotifyAgent{
|
||||
ds: ds,
|
||||
id: conf.Server.Spotify.ID,
|
||||
secret: conf.Server.Spotify.Secret,
|
||||
}
|
||||
hc := &http.Client{
|
||||
Timeout: consts.DefaultHttpClientTimeOut,
|
||||
}
|
||||
chc := cache.NewHTTPClient(hc, consts.DefaultHttpClientTimeOut)
|
||||
l.client = newClient(l.id, l.secret, chc)
|
||||
return l
|
||||
}
|
||||
|
||||
func (s *spotifyAgent) AgentName() string {
|
||||
return spotifyAgentName
|
||||
}
|
||||
|
||||
func (s *spotifyAgent) GetArtistImages(ctx context.Context, id, name, mbid string) ([]agents.ExternalImage, error) {
|
||||
a, err := s.searchArtist(ctx, name)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
log.Warn(ctx, "Artist not found in Spotify", "artist", name)
|
||||
} else {
|
||||
log.Error(ctx, "Error calling Spotify", "artist", name, err)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var res []agents.ExternalImage
|
||||
for _, img := range a.Images {
|
||||
res = append(res, agents.ExternalImage{
|
||||
URL: img.URL,
|
||||
Size: img.Width,
|
||||
})
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (s *spotifyAgent) searchArtist(ctx context.Context, name string) (*Artist, error) {
|
||||
artists, err := s.client.searchArtists(ctx, name, 40)
|
||||
if err != nil || len(artists) == 0 {
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
name = strings.ToLower(name)
|
||||
|
||||
// Sort results, prioritizing artists with images, with similar names and with high popularity, in this order
|
||||
sort.Slice(artists, func(i, j int) bool {
|
||||
ai := fmt.Sprintf("%-5t-%03d-%04d", len(artists[i].Images) == 0, smetrics.WagnerFischer(name, strings.ToLower(artists[i].Name), 1, 1, 2), 1000-artists[i].Popularity)
|
||||
aj := fmt.Sprintf("%-5t-%03d-%04d", len(artists[j].Images) == 0, smetrics.WagnerFischer(name, strings.ToLower(artists[j].Name), 1, 1, 2), 1000-artists[j].Popularity)
|
||||
return ai < aj
|
||||
})
|
||||
|
||||
// If the first one has the same name, that's the one
|
||||
if strings.ToLower(artists[0].Name) != name {
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
return &artists[0], err
|
||||
}
|
||||
|
||||
func init() {
|
||||
conf.AddHook(func() {
|
||||
agents.Register(spotifyAgentName, spotifyConstructor)
|
||||
})
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
package spotify
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/navidrome/navidrome/log"
|
||||
"github.com/navidrome/navidrome/tests"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestSpotify(t *testing.T) {
|
||||
tests.Init(t, false)
|
||||
log.SetLevel(log.LevelFatal)
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Spotify Test Suite")
|
||||
}
|
||||
@ -27,7 +27,6 @@ import (
|
||||
_ "github.com/navidrome/navidrome/adapters/gotaglib"
|
||||
_ "github.com/navidrome/navidrome/adapters/lastfm"
|
||||
_ "github.com/navidrome/navidrome/adapters/listenbrainz"
|
||||
_ "github.com/navidrome/navidrome/adapters/spotify"
|
||||
_ "github.com/navidrome/navidrome/adapters/taglib"
|
||||
)
|
||||
|
||||
|
||||
@ -39,7 +39,6 @@ import (
|
||||
_ "github.com/navidrome/navidrome/adapters/gotaglib"
|
||||
_ "github.com/navidrome/navidrome/adapters/lastfm"
|
||||
_ "github.com/navidrome/navidrome/adapters/listenbrainz"
|
||||
_ "github.com/navidrome/navidrome/adapters/spotify"
|
||||
_ "github.com/navidrome/navidrome/adapters/taglib"
|
||||
)
|
||||
|
||||
|
||||
@ -105,7 +105,6 @@ type configOptions struct {
|
||||
Inspect inspectOptions `json:",omitzero"`
|
||||
Subsonic subsonicOptions `json:",omitzero"`
|
||||
LastFM lastfmOptions `json:",omitzero"`
|
||||
Spotify spotifyOptions `json:",omitzero"`
|
||||
Deezer deezerOptions `json:",omitzero"`
|
||||
ListenBrainz listenBrainzOptions `json:",omitzero"`
|
||||
EnableScrobbleHistory bool
|
||||
@ -188,11 +187,6 @@ type lastfmOptions struct {
|
||||
Languages []string // Computed from Language, split by comma
|
||||
}
|
||||
|
||||
type spotifyOptions struct {
|
||||
ID string
|
||||
Secret string //nolint:gosec
|
||||
}
|
||||
|
||||
type deezerOptions struct {
|
||||
Enabled bool
|
||||
Language string
|
||||
@ -347,6 +341,10 @@ func Load(noConfigDump bool) {
|
||||
os.Exit(1)
|
||||
}
|
||||
log.SetOutput(out)
|
||||
} else if os.Getenv("JOURNAL_STREAM") != "" {
|
||||
// When running under systemd, prepend syslog priority prefixes so
|
||||
// journald assigns the correct severity to each log line.
|
||||
log.EnableJournalFormat()
|
||||
}
|
||||
|
||||
log.SetLevelString(Server.LogLevel)
|
||||
@ -412,6 +410,7 @@ func Load(noConfigDump bool) {
|
||||
// Parse Deezer.Language into Languages slice (comma-separated, with fallback to DefaultInfoLanguage)
|
||||
Server.Deezer.Languages = parseLanguages(Server.Deezer.Language)
|
||||
|
||||
// Deprecated options
|
||||
logDeprecatedOptions("Scanner.GenreSeparators", "")
|
||||
logDeprecatedOptions("Scanner.GroupAlbumReleases", "")
|
||||
logDeprecatedOptions("DevEnableBufferedScrobble", "") // Deprecated: Buffered scrobbling is now always enabled and this option is ignored
|
||||
@ -421,6 +420,9 @@ func Load(noConfigDump bool) {
|
||||
logDeprecatedOptions("HTTPSecurityHeaders.CustomFrameOptionsValue", "HTTPHeaders.FrameOptions")
|
||||
logDeprecatedOptions("CoverJpegQuality", "CoverArtQuality")
|
||||
|
||||
// Removed options
|
||||
logRemovedOptions("Spotify.ID", "Spotify.Secret")
|
||||
|
||||
// Call init hooks
|
||||
for _, hook := range hooks {
|
||||
hook()
|
||||
@ -445,6 +447,23 @@ func logDeprecatedOptions(oldName, newName string) {
|
||||
}
|
||||
}
|
||||
|
||||
// logRemovedOptions checks if the option is set, and if yes, outputs a warning message saying the option is
|
||||
// not available anymore
|
||||
func logRemovedOptions(options ...string) {
|
||||
for _, option := range options {
|
||||
envVar := "ND_" + strings.ToUpper(strings.ReplaceAll(option, ".", "_"))
|
||||
logWarning := func(option string) {
|
||||
log.Warn(fmt.Sprintf("Option '%s' is not available anymore and will be ignored. Please remove it from your config", option))
|
||||
}
|
||||
if viper.InConfig(option) {
|
||||
logWarning(option)
|
||||
}
|
||||
if os.Getenv(envVar) != "" {
|
||||
logWarning(envVar)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// mapDeprecatedOption is used to provide backwards compatibility for deprecated options. It should be called after
|
||||
// the config has been read by viper, but before unmarshalling it into the Config struct.
|
||||
func mapDeprecatedOption(legacyName, newName string) {
|
||||
@ -483,7 +502,6 @@ func disableExternalServices() {
|
||||
Server.EnableInsightsCollector = false
|
||||
Server.EnableM3UExternalAlbumArt = false
|
||||
Server.LastFM.Enabled = false
|
||||
Server.Spotify.ID = ""
|
||||
Server.Deezer.Enabled = false
|
||||
Server.ListenBrainz.Enabled = false
|
||||
Server.Agents = ""
|
||||
@ -714,14 +732,12 @@ func setViperDefaults() {
|
||||
viper.SetDefault("subsonic.folderbrowsing", true)
|
||||
viper.SetDefault("subsonic.legacyclients", "DSub")
|
||||
viper.SetDefault("subsonic.minimalclients", "SubMusic")
|
||||
viper.SetDefault("agents", "deezer,lastfm,spotify")
|
||||
viper.SetDefault("agents", "deezer,lastfm,listenbrainz")
|
||||
viper.SetDefault("lastfm.enabled", true)
|
||||
viper.SetDefault("lastfm.language", consts.DefaultInfoLanguage)
|
||||
viper.SetDefault("lastfm.apikey", "")
|
||||
viper.SetDefault("lastfm.secret", "")
|
||||
viper.SetDefault("lastfm.scrobblefirstartistonly", false)
|
||||
viper.SetDefault("spotify.id", "")
|
||||
viper.SetDefault("spotify.secret", "")
|
||||
viper.SetDefault("deezer.enabled", true)
|
||||
viper.SetDefault("deezer.language", consts.DefaultInfoLanguage)
|
||||
viper.SetDefault("listenbrainz.enabled", true)
|
||||
|
||||
@ -7,6 +7,6 @@ A new agent must comply with these simple implementation rules:
|
||||
2) Implement one or more of the `*Retriever()` interfaces. That's where the agent's logic resides.
|
||||
3) Register itself (in its `init()` function).
|
||||
|
||||
For an agent to be used it needs to be listed in the `Agents` config option (default is `"lastfm,spotify"`). The order dictates the priority of the agents
|
||||
For an agent to be used it needs to be listed in the `Agents` config option (default is `"deezer,lastfm"`). The order dictates the priority of the agents
|
||||
|
||||
For a simple Agent example, look at the [local_agent](local_agent.go) agent source code.
|
||||
|
||||
@ -79,7 +79,7 @@ func newArtistArtworkReader(ctx context.Context, artwork *artwork, artID model.A
|
||||
}
|
||||
|
||||
func (a *artistReader) Key() string {
|
||||
hash := md5.Sum([]byte(conf.Server.Agents + conf.Server.Spotify.ID))
|
||||
hash := md5.Sum([]byte(conf.Server.Agents))
|
||||
return fmt.Sprintf(
|
||||
"%s.%t.%x",
|
||||
a.cacheKey.Key(),
|
||||
|
||||
1
core/external/provider_topsongs_test.go
vendored
1
core/external/provider_topsongs_test.go
vendored
@ -6,7 +6,6 @@ import (
|
||||
|
||||
_ "github.com/navidrome/navidrome/adapters/lastfm"
|
||||
_ "github.com/navidrome/navidrome/adapters/listenbrainz"
|
||||
_ "github.com/navidrome/navidrome/adapters/spotify"
|
||||
"github.com/navidrome/navidrome/conf"
|
||||
"github.com/navidrome/navidrome/conf/configtest"
|
||||
"github.com/navidrome/navidrome/core/agents"
|
||||
|
||||
@ -199,7 +199,6 @@ var staticData = sync.OnceValue(func() insights.Data {
|
||||
data.Config.EnableSharing = conf.Server.EnableSharing
|
||||
data.Config.EnableStarRating = conf.Server.EnableStarRating
|
||||
data.Config.EnableLastFM = conf.Server.LastFM.Enabled && conf.Server.LastFM.ApiKey != "" && conf.Server.LastFM.Secret != ""
|
||||
data.Config.EnableSpotify = conf.Server.Spotify.ID != "" && conf.Server.Spotify.Secret != ""
|
||||
data.Config.EnableListenBrainz = conf.Server.ListenBrainz.Enabled
|
||||
data.Config.EnableDeezer = conf.Server.Deezer.Enabled
|
||||
data.Config.EnableMediaFileCoverArt = conf.Server.EnableMediaFileCoverArt
|
||||
|
||||
@ -61,7 +61,6 @@ type Data struct {
|
||||
EnableListenBrainz bool `json:"enableListenBrainz,omitempty"`
|
||||
EnableDeezer bool `json:"enableDeezer,omitempty"`
|
||||
EnableMediaFileCoverArt bool `json:"enableMediaFileCoverArt,omitempty"`
|
||||
EnableSpotify bool `json:"enableSpotify,omitempty"`
|
||||
EnableJukebox bool `json:"enableJukebox,omitempty"`
|
||||
EnablePrometheus bool `json:"enablePrometheus,omitempty"`
|
||||
EnableCoverAnimation bool `json:"enableCoverAnimation,omitempty"`
|
||||
|
||||
41
log/journal.go
Normal file
41
log/journal.go
Normal file
@ -0,0 +1,41 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// journalFormatter wraps a logrus.Formatter and prepends a syslog priority
|
||||
// prefix (<N>) to each log line. When stderr is captured by systemd-journald,
|
||||
// this prefix tells journald the correct severity for each message.
|
||||
//
|
||||
// See https://www.freedesktop.org/software/systemd/man/sd-daemon.html
|
||||
type journalFormatter struct {
|
||||
inner logrus.Formatter
|
||||
}
|
||||
|
||||
// levelToPriority maps logrus levels to syslog priority values.
|
||||
// The mapping follows RFC 5424 severity levels.
|
||||
var levelToPriority = map[logrus.Level]int{
|
||||
logrus.PanicLevel: 0, // emerg
|
||||
logrus.FatalLevel: 2, // crit
|
||||
logrus.ErrorLevel: 3, // err
|
||||
logrus.WarnLevel: 4, // warning
|
||||
logrus.InfoLevel: 6, // info
|
||||
logrus.DebugLevel: 7, // debug
|
||||
logrus.TraceLevel: 7, // debug
|
||||
}
|
||||
|
||||
func (f *journalFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
||||
formatted, err := f.inner.Format(entry)
|
||||
if err != nil {
|
||||
return formatted, err
|
||||
}
|
||||
priority, ok := levelToPriority[entry.Level]
|
||||
if !ok {
|
||||
priority = 6 // default to info for unknown levels
|
||||
}
|
||||
prefix := []byte(fmt.Sprintf("<%d>", priority))
|
||||
return append(prefix, formatted...), nil
|
||||
}
|
||||
41
log/journal_test.go
Normal file
41
log/journal_test.go
Normal file
@ -0,0 +1,41 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var _ = Describe("journalFormatter", func() {
|
||||
var formatter *journalFormatter
|
||||
|
||||
BeforeEach(func() {
|
||||
inner := &logrus.TextFormatter{
|
||||
DisableTimestamp: true,
|
||||
DisableColors: true,
|
||||
}
|
||||
formatter = &journalFormatter{inner: inner}
|
||||
})
|
||||
|
||||
DescribeTable("prefixes log lines with syslog priority",
|
||||
func(level logrus.Level, expectedPrefix string) {
|
||||
entry := &logrus.Entry{
|
||||
Logger: logrus.New(),
|
||||
Level: level,
|
||||
Message: "test message",
|
||||
Data: logrus.Fields{},
|
||||
}
|
||||
out, err := formatter.Format(entry)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(string(out)).To(HavePrefix(expectedPrefix))
|
||||
},
|
||||
Entry("error", logrus.ErrorLevel, "<3>"),
|
||||
Entry("warning", logrus.WarnLevel, "<4>"),
|
||||
Entry("info", logrus.InfoLevel, "<6>"),
|
||||
Entry("debug", logrus.DebugLevel, "<7>"),
|
||||
Entry("trace", logrus.TraceLevel, "<7>"),
|
||||
Entry("fatal", logrus.FatalLevel, "<2>"),
|
||||
Entry("panic", logrus.PanicLevel, "<0>"),
|
||||
Entry("unknown level defaults to info", logrus.Level(99), "<6>"),
|
||||
)
|
||||
})
|
||||
10
log/log.go
10
log/log.go
@ -27,7 +27,6 @@ var redacted = &Hook{
|
||||
// Keys from the config
|
||||
"(ApiKey:\")[\\w]*",
|
||||
"(Secret:\")[\\w]*",
|
||||
"(Spotify.*ID:\")[\\w]*",
|
||||
"(PasswordEncryptionKey:[\\s]*\")[^\"]*",
|
||||
"(UserHeader:[\\s]*\")[^\"]*",
|
||||
"(TrustedSources:[\\s]*\")[^\"]*",
|
||||
@ -146,6 +145,15 @@ func SetOutput(w io.Writer) {
|
||||
defaultLogger.SetOutput(w)
|
||||
}
|
||||
|
||||
// EnableJournalFormat wraps the current logger formatter with syslog
|
||||
// priority prefixes for systemd-journald. Only call this when output
|
||||
// goes to stderr and JOURNAL_STREAM is set.
|
||||
func EnableJournalFormat() {
|
||||
loggerMu.Lock()
|
||||
defer loggerMu.Unlock()
|
||||
defaultLogger.Formatter = &journalFormatter{inner: defaultLogger.Formatter}
|
||||
}
|
||||
|
||||
// Redact applies redaction to a single string
|
||||
func Redact(msg string) string {
|
||||
r, _ := redacted.redact(msg)
|
||||
|
||||
@ -63,7 +63,7 @@ Folder = "/path/to/navidrome/plugins"
|
||||
Add the plugin to your agents list:
|
||||
|
||||
```toml
|
||||
Agents = "lastfm,spotify,wikimedia"
|
||||
Agents = "lastfm,wikimedia"
|
||||
```
|
||||
|
||||
## Testing with Extism CLI
|
||||
|
||||
@ -149,7 +149,7 @@
|
||||
},
|
||||
"requiredHosts": {
|
||||
"type": "array",
|
||||
"description": "List of required host patterns for HTTP requests (e.g., 'api.example.com', '*.spotify.com')",
|
||||
"description": "List of required host patterns for HTTP requests (e.g., 'api.example.com', '*.musicbrainz.org')",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
@ -189,7 +189,7 @@
|
||||
},
|
||||
"requiredHosts": {
|
||||
"type": "array",
|
||||
"description": "List of required host patterns for WebSocket connections (e.g., 'api.example.com', '*.spotify.com')",
|
||||
"description": "List of required host patterns for WebSocket connections (e.g., 'api.example.com', '*.musicbrainz.org')",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ type HTTPPermission struct {
|
||||
Reason *string `json:"reason,omitempty" yaml:"reason,omitempty" mapstructure:"reason,omitempty"`
|
||||
|
||||
// List of required host patterns for HTTP requests (e.g., 'api.example.com',
|
||||
// '*.spotify.com')
|
||||
// '*.musicbrainz.org')
|
||||
RequiredHosts []string `json:"requiredHosts,omitempty" yaml:"requiredHosts,omitempty" mapstructure:"requiredHosts,omitempty"`
|
||||
}
|
||||
|
||||
@ -251,6 +251,6 @@ type WebSocketPermission struct {
|
||||
Reason *string `json:"reason,omitempty" yaml:"reason,omitempty" mapstructure:"reason,omitempty"`
|
||||
|
||||
// List of required host patterns for WebSocket connections (e.g.,
|
||||
// 'api.example.com', '*.spotify.com')
|
||||
// 'api.example.com', '*.musicbrainz.org')
|
||||
RequiredHosts []string `json:"requiredHosts,omitempty" yaml:"requiredHosts,omitempty" mapstructure:"requiredHosts,omitempty"`
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ var _ = Describe("Manifest", func() {
|
||||
"permissions": {
|
||||
"http": {
|
||||
"reason": "Fetch metadata",
|
||||
"requiredHosts": ["api.example.com", "*.spotify.com"]
|
||||
"requiredHosts": ["api.example.com", "*.musicbrainz.org"]
|
||||
}
|
||||
}
|
||||
}`)
|
||||
@ -34,7 +34,7 @@ var _ = Describe("Manifest", func() {
|
||||
Expect(*m.Website).To(Equal("https://example.com"))
|
||||
Expect(m.Permissions.Http).ToNot(BeNil())
|
||||
Expect(*m.Permissions.Http.Reason).To(Equal("Fetch metadata"))
|
||||
Expect(m.Permissions.Http.RequiredHosts).To(ContainElements("api.example.com", "*.spotify.com"))
|
||||
Expect(m.Permissions.Http.RequiredHosts).To(ContainElements("api.example.com", "*.musicbrainz.org"))
|
||||
})
|
||||
|
||||
It("parses a minimal manifest", func() {
|
||||
|
||||
@ -91,11 +91,5 @@ func checkExternalCredentials() {
|
||||
} else {
|
||||
log.Debug("ListenBrainz integration is ENABLED", "ListenBrainz.BaseURL", conf.Server.ListenBrainz.BaseURL)
|
||||
}
|
||||
|
||||
if conf.Server.Spotify.ID == "" || conf.Server.Spotify.Secret == "" {
|
||||
log.Info("Spotify integration is not enabled: missing ID/Secret")
|
||||
} else {
|
||||
log.Debug("Spotify integration is ENABLED")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,13 +16,11 @@ import (
|
||||
// using partial masking (first and last character visible, middle replaced with *).
|
||||
// For values with 7+ characters: "secretvalue123" becomes "s***********3"
|
||||
// For values with <7 characters: "short" becomes "****"
|
||||
// Add field paths using dot notation (e.g., "LastFM.ApiKey", "Spotify.Secret")
|
||||
// Add field paths using dot notation (e.g., "LastFM.ApiKey")
|
||||
var sensitiveFieldsPartialMask = []string{
|
||||
"LastFM.ApiKey",
|
||||
"LastFM.Secret",
|
||||
"Prometheus.MetricsPath",
|
||||
"Spotify.ID",
|
||||
"Spotify.Secret",
|
||||
"DevAutoLoginUsername",
|
||||
}
|
||||
|
||||
|
||||
@ -78,7 +78,6 @@ var _ = Describe("Config API", func() {
|
||||
|
||||
It("redacts sensitive fields", func() {
|
||||
conf.Server.LastFM.ApiKey = "secretapikey123"
|
||||
conf.Server.Spotify.Secret = "spotifysecret456"
|
||||
conf.Server.PasswordEncryptionKey = "encryptionkey789"
|
||||
conf.Server.DevAutoCreateAdminPassword = "adminpassword123"
|
||||
conf.Server.Prometheus.Password = "prometheuspass"
|
||||
@ -97,11 +96,6 @@ var _ = Describe("Config API", func() {
|
||||
Expect(ok).To(BeTrue())
|
||||
Expect(lastfm["ApiKey"]).To(Equal("s*************3"))
|
||||
|
||||
// Check Spotify.Secret (partially masked)
|
||||
spotify, ok := resp.Config["Spotify"].(map[string]any)
|
||||
Expect(ok).To(BeTrue())
|
||||
Expect(spotify["Secret"]).To(Equal("s**************6"))
|
||||
|
||||
// Check PasswordEncryptionKey (fully masked)
|
||||
Expect(resp.Config["PasswordEncryptionKey"]).To(Equal("****"))
|
||||
|
||||
@ -172,7 +166,6 @@ var _ = Describe("Config API", func() {
|
||||
var _ = Describe("redactValue function", func() {
|
||||
It("partially masks long sensitive values", func() {
|
||||
Expect(redactValue("LastFM.ApiKey", "ba46f0e84a")).To(Equal("b********a"))
|
||||
Expect(redactValue("Spotify.Secret", "verylongsecret123")).To(Equal("v***************3"))
|
||||
})
|
||||
|
||||
It("fully masks long sensitive values that should be completely hidden", func() {
|
||||
@ -183,7 +176,6 @@ var _ = Describe("redactValue function", func() {
|
||||
|
||||
It("fully masks short sensitive values", func() {
|
||||
Expect(redactValue("LastFM.Secret", "short")).To(Equal("****"))
|
||||
Expect(redactValue("Spotify.ID", "abc")).To(Equal("****"))
|
||||
Expect(redactValue("PasswordEncryptionKey", "12345")).To(Equal("****"))
|
||||
Expect(redactValue("DevAutoCreateAdminPassword", "short")).To(Equal("****"))
|
||||
Expect(redactValue("Prometheus.Password", "short")).To(Equal("****"))
|
||||
|
||||
@ -309,6 +309,14 @@ var _ = Describe("helpers", func() {
|
||||
Expect(child.Artist).To(Equal("Test Artist"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when MediaFile has an empty title", func() {
|
||||
It("still includes the title field in the response", func() {
|
||||
mf.Title = ""
|
||||
child := childFromMediaFile(ctx, mf)
|
||||
Expect(child.Title).To(Equal(""))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Describe("osChildFromMediaFile", func() {
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
{
|
||||
"id": "1",
|
||||
"isDir": false,
|
||||
"title": "",
|
||||
"bpm": 0,
|
||||
"comment": "",
|
||||
"sortName": "sort name",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.16.1" type="navidrome" serverVersion="v0.55.0" openSubsonic="true">
|
||||
<albumList>
|
||||
<album id="1" isDir="false" sortName="sort name" mediaType="album" musicBrainzId="00000000-0000-0000-0000-000000000000" displayArtist="Display artist" displayAlbumArtist="Display album artist" explicitStatus="explicit">
|
||||
<album id="1" isDir="false" title="" sortName="sort name" mediaType="album" musicBrainzId="00000000-0000-0000-0000-000000000000" displayArtist="Display artist" displayAlbumArtist="Display album artist" explicitStatus="explicit">
|
||||
<genres name="Genre 1"></genres>
|
||||
<genres name="Genre 2"></genres>
|
||||
<moods>mood1</moods>
|
||||
|
||||
@ -115,6 +115,7 @@
|
||||
{
|
||||
"id": "",
|
||||
"isDir": false,
|
||||
"title": "",
|
||||
"bpm": 0,
|
||||
"comment": "",
|
||||
"sortName": "",
|
||||
|
||||
@ -25,7 +25,7 @@
|
||||
<artist id="4" name="composer2"></artist>
|
||||
</contributors>
|
||||
</child>
|
||||
<child id="" isDir="false">
|
||||
<child id="" isDir="false" title="">
|
||||
<replayGain trackGain="0" albumGain="0" trackPeak="0" albumPeak="0" baseGain="0" fallbackGain="0"></replayGain>
|
||||
</child>
|
||||
</directory>
|
||||
|
||||
@ -8,7 +8,8 @@
|
||||
"child": [
|
||||
{
|
||||
"id": "1",
|
||||
"isDir": false
|
||||
"isDir": false,
|
||||
"title": ""
|
||||
}
|
||||
],
|
||||
"id": "",
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.16.1" type="navidrome" serverVersion="v0.55.0" openSubsonic="true">
|
||||
<directory id="" name="">
|
||||
<child id="1" isDir="false"></child>
|
||||
<child id="1" isDir="false" title=""></child>
|
||||
</directory>
|
||||
</subsonic-response>
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
{
|
||||
"id": "1",
|
||||
"isDir": false,
|
||||
"title": "",
|
||||
"bpm": 0,
|
||||
"comment": "",
|
||||
"sortName": "",
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.16.1" type="navidrome" serverVersion="v0.55.0" openSubsonic="true">
|
||||
<directory id="" name="">
|
||||
<child id="1" isDir="false"></child>
|
||||
<child id="1" isDir="false" title=""></child>
|
||||
</directory>
|
||||
</subsonic-response>
|
||||
|
||||
@ -135,7 +135,7 @@ type Child struct {
|
||||
Id string `xml:"id,attr" json:"id"`
|
||||
Parent string `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
||||
IsDir bool `xml:"isDir,attr" json:"isDir"`
|
||||
Title string `xml:"title,attr,omitempty" json:"title,omitempty"`
|
||||
Title string `xml:"title,attr" json:"title"`
|
||||
Name string `xml:"name,attr,omitempty" json:"name,omitempty"`
|
||||
Album string `xml:"album,attr,omitempty" json:"album,omitempty"`
|
||||
Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"`
|
||||
|
||||
@ -13,7 +13,12 @@ import { linkToRecord, useListContext, Loading } from 'react-admin'
|
||||
import { withContentRect } from 'react-measure'
|
||||
import { useDrag } from 'react-dnd'
|
||||
import subsonic from '../subsonic'
|
||||
import { AlbumContextMenu, PlayButton, ArtistLinkField } from '../common'
|
||||
import {
|
||||
AlbumContextMenu,
|
||||
PlayButton,
|
||||
ArtistLinkField,
|
||||
OverflowTooltip,
|
||||
} from '../common'
|
||||
import { DraggableTypes } from '../consts'
|
||||
import clsx from 'clsx'
|
||||
import { AlbumDatesField } from './AlbumDatesField.jsx'
|
||||
@ -198,7 +203,9 @@ const AlbumGridTile = ({ showArtist, record, basePath, ...props }) => {
|
||||
to={linkToRecord(basePath, record.id, 'show')}
|
||||
>
|
||||
<span>
|
||||
<Typography className={classes.albumName}>{record.name}</Typography>
|
||||
<OverflowTooltip title={record.name}>
|
||||
<Typography className={classes.albumName}>{record.name}</Typography>
|
||||
</OverflowTooltip>
|
||||
{record.tags && record.tags['albumversion'] && (
|
||||
<Typography className={classes.albumVersion}>
|
||||
{record.tags['albumversion']}
|
||||
|
||||
90
ui/src/common/OverflowTooltip.jsx
Normal file
90
ui/src/common/OverflowTooltip.jsx
Normal file
@ -0,0 +1,90 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Tooltip } from '@material-ui/core'
|
||||
import { makeStyles, alpha } from '@material-ui/core/styles'
|
||||
import grey from '@material-ui/core/colors/grey'
|
||||
|
||||
const useStyles = makeStyles(
|
||||
(theme) => ({
|
||||
tooltip: {
|
||||
backgroundColor:
|
||||
theme.palette.type === 'dark'
|
||||
? alpha(grey[700], 0.92)
|
||||
: alpha(grey[300], 0.92),
|
||||
color:
|
||||
theme.palette.type === 'dark'
|
||||
? theme.palette.common.white
|
||||
: theme.palette.common.black,
|
||||
borderRadius: theme.shape.borderRadius,
|
||||
...theme.typography.body2,
|
||||
padding: theme.spacing(0.5, 1),
|
||||
maxWidth: 300,
|
||||
},
|
||||
}),
|
||||
{ name: 'NDOverflowTooltip' },
|
||||
)
|
||||
|
||||
const transitionProps = { timeout: 0 }
|
||||
|
||||
export const OverflowTooltip = ({
|
||||
children,
|
||||
title,
|
||||
placement = 'bottom-start',
|
||||
}) => {
|
||||
const classes = useStyles()
|
||||
const textRef = React.useRef(null)
|
||||
const [isOverflowing, setIsOverflowing] = React.useState(false)
|
||||
const tooltipClasses = React.useMemo(
|
||||
() => ({ tooltip: classes.tooltip }),
|
||||
[classes.tooltip],
|
||||
)
|
||||
|
||||
React.useLayoutEffect(() => {
|
||||
const el = textRef.current
|
||||
if (!el) return
|
||||
|
||||
const checkOverflow = () => {
|
||||
setIsOverflowing(el.scrollWidth > el.clientWidth)
|
||||
}
|
||||
|
||||
const resizeObserver = new ResizeObserver(checkOverflow)
|
||||
resizeObserver.observe(el)
|
||||
|
||||
checkOverflow()
|
||||
|
||||
return () => resizeObserver.disconnect()
|
||||
}, [])
|
||||
|
||||
const mergedRef = React.useCallback(
|
||||
(el) => {
|
||||
textRef.current = el
|
||||
|
||||
const { ref } = children
|
||||
if (typeof ref === 'function') {
|
||||
ref(el)
|
||||
} else if (ref && typeof ref === 'object') {
|
||||
ref.current = el
|
||||
}
|
||||
},
|
||||
[children],
|
||||
)
|
||||
|
||||
return (
|
||||
<Tooltip
|
||||
title={title}
|
||||
disableHoverListener={!isOverflowing}
|
||||
disableTouchListener
|
||||
placement={placement}
|
||||
TransitionProps={transitionProps}
|
||||
classes={tooltipClasses}
|
||||
>
|
||||
{React.cloneElement(children, { ref: mergedRef })}
|
||||
</Tooltip>
|
||||
)
|
||||
}
|
||||
|
||||
OverflowTooltip.propTypes = {
|
||||
children: PropTypes.element.isRequired,
|
||||
title: PropTypes.string.isRequired,
|
||||
placement: PropTypes.string,
|
||||
}
|
||||
@ -41,4 +41,5 @@ export * from './formatRange.js'
|
||||
export * from './playlistUtils.js'
|
||||
export * from './PathField.jsx'
|
||||
export * from './ParticipantsInfo'
|
||||
export * from './OverflowTooltip'
|
||||
export * from './useSearchRefocus'
|
||||
|
||||
@ -7,6 +7,8 @@ export const M3U_MIME_TYPE = 'audio/x-mpegurl'
|
||||
|
||||
export const AUTO_THEME_ID = 'AUTO_THEME_ID'
|
||||
|
||||
export const AUTO_THEME_CONFIG_VALUE = 'Auto'
|
||||
|
||||
export const DraggableTypes = {
|
||||
SONG: 'song',
|
||||
ALBUM: 'album',
|
||||
|
||||
@ -12,7 +12,7 @@ import QueueMusicOutlinedIcon from '@material-ui/icons/QueueMusicOutlined'
|
||||
import { BiCog } from 'react-icons/bi'
|
||||
import { useDrop } from 'react-dnd'
|
||||
import SubMenu from './SubMenu'
|
||||
import { canChangeTracks } from '../common'
|
||||
import { canChangeTracks, OverflowTooltip } from '../common'
|
||||
import { DraggableTypes } from '../consts'
|
||||
import config from '../config'
|
||||
|
||||
@ -39,9 +39,11 @@ const PlaylistMenuItemLink = ({ pls, sidebarIsOpen }) => {
|
||||
<MenuItemLink
|
||||
to={`/playlist/${pls.id}/show`}
|
||||
primaryText={
|
||||
<Typography variant="inherit" noWrap ref={dropRef}>
|
||||
{pls.name}
|
||||
</Typography>
|
||||
<OverflowTooltip title={pls.name} placement="right">
|
||||
<Typography variant="inherit" noWrap ref={dropRef}>
|
||||
{pls.name}
|
||||
</Typography>
|
||||
</OverflowTooltip>
|
||||
}
|
||||
sidebarIsOpen={sidebarIsOpen}
|
||||
dense={false}
|
||||
|
||||
@ -19,6 +19,7 @@ import {
|
||||
DurationField,
|
||||
SizeField,
|
||||
isWritable,
|
||||
OverflowTooltip,
|
||||
} from '../common'
|
||||
import config from '../config'
|
||||
import subsonic from '../subsonic'
|
||||
@ -274,12 +275,14 @@ const PlaylistDetails = (props) => {
|
||||
</div>
|
||||
<div className={classes.details}>
|
||||
<CardContent className={classes.content}>
|
||||
<Typography
|
||||
variant={isDesktop ? 'h5' : 'h6'}
|
||||
className={classes.title}
|
||||
>
|
||||
{record.name || translate('ra.page.loading')}
|
||||
</Typography>
|
||||
<OverflowTooltip title={record.name || ''}>
|
||||
<Typography
|
||||
variant={isDesktop ? 'h5' : 'h6'}
|
||||
className={classes.title}
|
||||
>
|
||||
{record.name || translate('ra.page.loading')}
|
||||
</Typography>
|
||||
</OverflowTooltip>
|
||||
<Typography component="p" className={classes.stats}>
|
||||
{record.songCount ? (
|
||||
<span>
|
||||
|
||||
@ -1,8 +1,12 @@
|
||||
import { CHANGE_THEME } from '../actions'
|
||||
import { AUTO_THEME_ID, AUTO_THEME_CONFIG_VALUE } from '../consts'
|
||||
import config from '../config'
|
||||
import themes from '../themes'
|
||||
|
||||
const defaultTheme = () => {
|
||||
if (config.defaultTheme === AUTO_THEME_CONFIG_VALUE) {
|
||||
return AUTO_THEME_ID
|
||||
}
|
||||
return (
|
||||
Object.keys(themes).find(
|
||||
(t) => themes[t].themeName === config.defaultTheme,
|
||||
|
||||
32
ui/src/reducers/themeReducer.test.js
Normal file
32
ui/src/reducers/themeReducer.test.js
Normal file
@ -0,0 +1,32 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { AUTO_THEME_ID, AUTO_THEME_CONFIG_VALUE } from '../consts'
|
||||
|
||||
describe('themeReducer', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
})
|
||||
|
||||
it.each([
|
||||
{
|
||||
configTheme: AUTO_THEME_CONFIG_VALUE,
|
||||
expected: AUTO_THEME_ID,
|
||||
description: 'is "Auto"',
|
||||
},
|
||||
{ configTheme: 'Dark', expected: 'DarkTheme', description: 'is "Dark"' },
|
||||
{
|
||||
configTheme: 'NonExistent',
|
||||
expected: 'DarkTheme',
|
||||
description: 'is unrecognized',
|
||||
},
|
||||
])(
|
||||
'returns $expected when defaultTheme config $description',
|
||||
async ({ configTheme, expected }) => {
|
||||
vi.doMock('../config', () => ({
|
||||
default: { defaultTheme: configTheme },
|
||||
}))
|
||||
const { themeReducer } = await import('./themeReducer')
|
||||
const result = themeReducer(undefined, { type: 'UNKNOWN' })
|
||||
expect(result).toBe(expected)
|
||||
},
|
||||
)
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user