mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-14 11:17:19 +03:00
Expose Last.fm's ApiKey to UI
This commit is contained in:
parent
143cde37e5
commit
1f997357a9
@ -214,8 +214,8 @@ func init() {
|
|||||||
viper.SetDefault("agents", "lastfm,spotify")
|
viper.SetDefault("agents", "lastfm,spotify")
|
||||||
viper.SetDefault("lastfm.enabled", true)
|
viper.SetDefault("lastfm.enabled", true)
|
||||||
viper.SetDefault("lastfm.language", "en")
|
viper.SetDefault("lastfm.language", "en")
|
||||||
viper.SetDefault("lastfm.apikey", "")
|
viper.SetDefault("lastfm.apikey", consts.LastFMAPIKey)
|
||||||
viper.SetDefault("lastfm.secret", "")
|
viper.SetDefault("lastfm.secret", consts.LastFMAPISecret)
|
||||||
viper.SetDefault("spotify.id", "")
|
viper.SetDefault("spotify.id", "")
|
||||||
viper.SetDefault("spotify.secret", "")
|
viper.SetDefault("spotify.secret", "")
|
||||||
|
|
||||||
|
@ -61,6 +61,12 @@ const (
|
|||||||
DefaultCacheCleanUpInterval = 10 * time.Minute
|
DefaultCacheCleanUpInterval = 10 * time.Minute
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Shared secrets (only add here "secrets" that can be public)
|
||||||
|
const (
|
||||||
|
LastFMAPIKey = "9b94a5515ea66b2da3ec03c12300327e"
|
||||||
|
LastFMAPISecret = "74cb6557cec7171d921af5d7d887c587" // nolint:gosec
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
DefaultTranscodings = []map[string]interface{}{
|
DefaultTranscodings = []map[string]interface{}{
|
||||||
{
|
{
|
||||||
|
@ -13,8 +13,6 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
lastFMAgentName = "lastfm"
|
lastFMAgentName = "lastfm"
|
||||||
lastFMAPIKey = "9b94a5515ea66b2da3ec03c12300327e"
|
|
||||||
lastFMAPISecret = "74cb6557cec7171d921af5d7d887c587" // nolint:gosec
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type lastfmAgent struct {
|
type lastfmAgent struct {
|
||||||
@ -29,12 +27,8 @@ func lastFMConstructor(ctx context.Context) agents.Interface {
|
|||||||
l := &lastfmAgent{
|
l := &lastfmAgent{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
lang: conf.Server.LastFM.Language,
|
lang: conf.Server.LastFM.Language,
|
||||||
apiKey: lastFMAPIKey,
|
apiKey: conf.Server.LastFM.ApiKey,
|
||||||
secret: lastFMAPISecret,
|
secret: conf.Server.LastFM.Secret,
|
||||||
}
|
|
||||||
if conf.Server.LastFM.ApiKey != "" {
|
|
||||||
l.apiKey = conf.Server.LastFM.ApiKey
|
|
||||||
l.secret = conf.Server.LastFM.Secret
|
|
||||||
}
|
}
|
||||||
hc := utils.NewCachedHTTPClient(http.DefaultClient, consts.DefaultCachedHttpClientTTL)
|
hc := utils.NewCachedHTTPClient(http.DefaultClient, consts.DefaultCachedHttpClientTTL)
|
||||||
l.client = NewClient(l.apiKey, l.secret, l.lang, hc)
|
l.client = NewClient(l.apiKey, l.secret, l.lang, hc)
|
@ -22,18 +22,13 @@ const (
|
|||||||
|
|
||||||
var _ = Describe("lastfmAgent", func() {
|
var _ = Describe("lastfmAgent", func() {
|
||||||
Describe("lastFMConstructor", func() {
|
Describe("lastFMConstructor", func() {
|
||||||
It("uses default api key and language if not configured", func() {
|
|
||||||
conf.Server.LastFM.ApiKey = ""
|
|
||||||
agent := lastFMConstructor(context.Background())
|
|
||||||
Expect(agent.(*lastfmAgent).apiKey).To(Equal(lastFMAPIKey))
|
|
||||||
Expect(agent.(*lastfmAgent).lang).To(Equal("en"))
|
|
||||||
})
|
|
||||||
|
|
||||||
It("uses configured api key and language", func() {
|
It("uses configured api key and language", func() {
|
||||||
conf.Server.LastFM.ApiKey = "123"
|
conf.Server.LastFM.ApiKey = "123"
|
||||||
|
conf.Server.LastFM.Secret = "secret"
|
||||||
conf.Server.LastFM.Language = "pt"
|
conf.Server.LastFM.Language = "pt"
|
||||||
agent := lastFMConstructor(context.Background())
|
agent := lastFMConstructor(context.Background())
|
||||||
Expect(agent.(*lastfmAgent).apiKey).To(Equal("123"))
|
Expect(agent.(*lastfmAgent).apiKey).To(Equal("123"))
|
||||||
|
Expect(agent.(*lastfmAgent).secret).To(Equal("secret"))
|
||||||
Expect(agent.(*lastfmAgent).lang).To(Equal("pt"))
|
Expect(agent.(*lastfmAgent).lang).To(Equal("pt"))
|
||||||
})
|
})
|
||||||
})
|
})
|
@ -30,13 +30,13 @@ type Router struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewRouter(ds model.DataStore) *Router {
|
func NewRouter(ds model.DataStore) *Router {
|
||||||
r := &Router{ds: ds, apiKey: lastFMAPIKey, secret: lastFMAPISecret}
|
r := &Router{
|
||||||
|
ds: ds,
|
||||||
|
apiKey: conf.Server.LastFM.ApiKey,
|
||||||
|
secret: conf.Server.LastFM.Secret,
|
||||||
|
}
|
||||||
r.sessionKeys = &sessionKeys{ds: ds}
|
r.sessionKeys = &sessionKeys{ds: ds}
|
||||||
r.Handler = r.routes()
|
r.Handler = r.routes()
|
||||||
if conf.Server.LastFM.ApiKey != "" {
|
|
||||||
r.apiKey = conf.Server.LastFM.ApiKey
|
|
||||||
r.secret = conf.Server.LastFM.Secret
|
|
||||||
}
|
|
||||||
r.client = NewClient(r.apiKey, r.secret, "en", http.DefaultClient)
|
r.client = NewClient(r.apiKey, r.secret, "en", http.DefaultClient)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ func serveIndex(ds model.DataStore, fs fs.FS) http.HandlerFunc {
|
|||||||
"enableUserEditing": conf.Server.EnableUserEditing,
|
"enableUserEditing": conf.Server.EnableUserEditing,
|
||||||
"devEnableShare": conf.Server.DevEnableShare,
|
"devEnableShare": conf.Server.DevEnableShare,
|
||||||
"devEnableScrobble": conf.Server.DevEnableScrobble,
|
"devEnableScrobble": conf.Server.DevEnableScrobble,
|
||||||
|
"lastFMApiKey": conf.Server.LastFM.ApiKey,
|
||||||
}
|
}
|
||||||
auth := handleLoginFromHeaders(ds, r)
|
auth := handleLoginFromHeaders(ds, r)
|
||||||
if auth != nil {
|
if auth != nil {
|
||||||
|
@ -209,6 +209,17 @@ var _ = Describe("serveIndex", func() {
|
|||||||
config := extractAppConfig(w.Body.String())
|
config := extractAppConfig(w.Body.String())
|
||||||
Expect(config).To(HaveKeyWithValue("devEnableScrobble", false))
|
Expect(config).To(HaveKeyWithValue("devEnableScrobble", false))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("sets the lastFMApiKey", func() {
|
||||||
|
conf.Server.LastFM.ApiKey = "APIKEY-123"
|
||||||
|
r := httptest.NewRequest("GET", "/index.html", nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
|
serveIndex(ds, fs)(w, r)
|
||||||
|
|
||||||
|
config := extractAppConfig(w.Body.String())
|
||||||
|
Expect(config).To(HaveKeyWithValue("lastFMApiKey", "APIKEY-123"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
var appConfigRegex = regexp.MustCompile(`(?m)window.__APP_CONFIG__="([^"]*)`)
|
var appConfigRegex = regexp.MustCompile(`(?m)window.__APP_CONFIG__="([^"]*)`)
|
||||||
|
@ -20,6 +20,7 @@ const defaultConfig = {
|
|||||||
enableUserEditing: true,
|
enableUserEditing: true,
|
||||||
devEnableShare: true,
|
devEnableShare: true,
|
||||||
devEnableScrobble: true,
|
devEnableScrobble: true,
|
||||||
|
lastFMApiKey: '9b94a5515ea66b2da3ec03c12300327e',
|
||||||
}
|
}
|
||||||
|
|
||||||
let config
|
let config
|
||||||
|
Loading…
x
Reference in New Issue
Block a user