From 3bd6f82c804bce5618149aea95591dc82ca6b720 Mon Sep 17 00:00:00 2001 From: Steve Richter Date: Wed, 17 Nov 2021 21:11:53 -0500 Subject: [PATCH] Rename ListenBrainz config flag and enable by default (#1443) --- cmd/root.go | 2 +- conf/configuration.go | 16 ++++++++++------ core/agents/listenbrainz/agent.go | 2 +- server/serve_index.go | 2 +- server/serve_index_test.go | 6 +++--- ui/src/config.js | 2 +- ui/src/personal/Personal.js | 2 +- ui/src/player/PlayerEdit.js | 2 +- 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 238042c5..dcb75ca6 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -80,7 +80,7 @@ func startServer() (func() error, func(err error)) { if conf.Server.LastFM.Enabled { a.MountRouter("LastFM Auth", consts.URLPathNativeAPI+"/lastfm", CreateLastFMRouter()) } - if conf.Server.DevListenBrainzEnabled { + if conf.Server.ListenBrainz.Enabled { a.MountRouter("ListenBrainz Auth", consts.URLPathNativeAPI+"/listenbrainz", CreateListenBrainzRouter()) } return a.Run(fmt.Sprintf("%s:%d", conf.Server.Address, conf.Server.Port)) diff --git a/conf/configuration.go b/conf/configuration.go index 9f33472f..c4f9ba61 100644 --- a/conf/configuration.go +++ b/conf/configuration.go @@ -59,9 +59,10 @@ type configOptions struct { Scanner scannerOptions - Agents string - LastFM lastfmOptions - Spotify spotifyOptions + Agents string + LastFM lastfmOptions + Spotify spotifyOptions + ListenBrainz listenBrainzOptions // DevFlags. These are used to enable/disable debugging and incomplete features DevLogSourceLine bool @@ -75,7 +76,6 @@ type configOptions struct { DevSidebarPlaylists bool DevEnableBufferedScrobble bool DevShowArtistPage bool - DevListenBrainzEnabled bool } type scannerOptions struct { @@ -95,6 +95,10 @@ type spotifyOptions struct { Secret string } +type listenBrainzOptions struct { + Enabled bool +} + var ( Server = &configOptions{} hooks []func() @@ -153,10 +157,10 @@ func disableExternalServices() { log.Info("All external integrations are DISABLED!") Server.LastFM.Enabled = false Server.Spotify.ID = "" + Server.ListenBrainz.Enabled = false if Server.UILoginBackgroundURL == consts.DefaultUILoginBackgroundURL { Server.UILoginBackgroundURL = consts.DefaultUILoginBackgroundURLOffline } - Server.DevListenBrainzEnabled = false } func validateScanSchedule() error { @@ -246,6 +250,7 @@ func init() { viper.SetDefault("lastfm.secret", consts.LastFMAPISecret) viper.SetDefault("spotify.id", "") viper.SetDefault("spotify.secret", "") + viper.SetDefault("listenbrainz.enabled", true) // DevFlags. These are used to enable/disable debugging and incomplete features viper.SetDefault("devlogsourceline", false) @@ -258,7 +263,6 @@ func init() { viper.SetDefault("devenablebufferedscrobble", true) viper.SetDefault("devsidebarplaylists", true) viper.SetDefault("devshowartistpage", true) - viper.SetDefault("devlistenbrainzenabled", false) } func InitConfig(cfgFile string) { diff --git a/core/agents/listenbrainz/agent.go b/core/agents/listenbrainz/agent.go index bb699a8a..05b80be3 100644 --- a/core/agents/listenbrainz/agent.go +++ b/core/agents/listenbrainz/agent.go @@ -104,7 +104,7 @@ func (l *listenBrainzAgent) IsAuthorized(ctx context.Context, userId string) boo func init() { conf.AddHook(func() { - if conf.Server.DevListenBrainzEnabled { + if conf.Server.ListenBrainz.Enabled { scrobbler.Register(listenBrainzAgentName, func(ds model.DataStore) scrobbler.Scrobbler { return listenBrainzConstructor(ds) }) diff --git a/server/serve_index.go b/server/serve_index.go index e2f8a5ca..399dde1e 100644 --- a/server/serve_index.go +++ b/server/serve_index.go @@ -49,7 +49,7 @@ func serveIndex(ds model.DataStore, fs fs.FS) http.HandlerFunc { "lastFMEnabled": conf.Server.LastFM.Enabled, "lastFMApiKey": conf.Server.LastFM.ApiKey, "devShowArtistPage": conf.Server.DevShowArtistPage, - "devListenBrainzEnabled": conf.Server.DevListenBrainzEnabled, + "listenBrainzEnabled": conf.Server.ListenBrainz.Enabled, } auth := handleLoginFromHeaders(ds, r) if auth != nil { diff --git a/server/serve_index_test.go b/server/serve_index_test.go index 6b04e62b..00bd88ea 100644 --- a/server/serve_index_test.go +++ b/server/serve_index_test.go @@ -266,15 +266,15 @@ var _ = Describe("serveIndex", func() { Expect(config).To(HaveKeyWithValue("devShowArtistPage", true)) }) - It("sets the devListenBrainzEnabled", func() { - conf.Server.DevListenBrainzEnabled = true + It("sets the listenBrainzEnabled", func() { + conf.Server.ListenBrainz.Enabled = true r := httptest.NewRequest("GET", "/index.html", nil) w := httptest.NewRecorder() serveIndex(ds, fs)(w, r) config := extractAppConfig(w.Body.String()) - Expect(config).To(HaveKeyWithValue("devListenBrainzEnabled", true)) + Expect(config).To(HaveKeyWithValue("listenBrainzEnabled", true)) }) }) diff --git a/ui/src/config.js b/ui/src/config.js index 965f26ae..18ad3499 100644 --- a/ui/src/config.js +++ b/ui/src/config.js @@ -23,9 +23,9 @@ const defaultConfig = { devSidebarPlaylists: true, lastFMEnabled: true, lastFMApiKey: '9b94a5515ea66b2da3ec03c12300327e', + listenBrainzEnabled: true, enableCoverAnimation: true, devShowArtistPage: true, - devListenBrainzEnabled: true, } let config diff --git a/ui/src/personal/Personal.js b/ui/src/personal/Personal.js index 7bee5dbb..86cea55c 100644 --- a/ui/src/personal/Personal.js +++ b/ui/src/personal/Personal.js @@ -26,7 +26,7 @@ const Personal = () => { {config.lastFMEnabled && } - {config.devListenBrainzEnabled && } + {config.listenBrainzEnabled && } ) diff --git a/ui/src/player/PlayerEdit.js b/ui/src/player/PlayerEdit.js index 58a695cb..60cff0a7 100644 --- a/ui/src/player/PlayerEdit.js +++ b/ui/src/player/PlayerEdit.js @@ -48,7 +48,7 @@ const PlayerEdit = (props) => ( ]} /> - {(config.lastFMEnabled || config.devListenBrainzEnabled) && ( + {(config.lastFMEnabled || config.listenBrainzEnabled) && ( )}