From babc48c29d6c82e6709ac0719034d097f1fce06d 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 | 18 +++++++++++------- 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, 20 insertions(+), 16 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 238042c5e..dcb75ca60 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 9cb7920cb..5376d6d91 100644 --- a/conf/configuration.go +++ b/conf/configuration.go @@ -59,10 +59,11 @@ type configOptions struct { Scanner scannerOptions - Agents string - LastFM lastfmOptions - Spotify spotifyOptions - LDAP ldapOptions + Agents string + LastFM lastfmOptions + Spotify spotifyOptions + LDAP ldapOptions + ListenBrainz listenBrainzOptions // DevFlags. These are used to enable/disable debugging and incomplete features DevLogSourceLine bool @@ -76,7 +77,6 @@ type configOptions struct { DevSidebarPlaylists bool DevEnableBufferedScrobble bool DevShowArtistPage bool - DevListenBrainzEnabled bool } type scannerOptions struct { @@ -106,6 +106,10 @@ type ldapOptions struct { Name string } +type listenBrainzOptions struct { + Enabled bool +} + var ( Server = &configOptions{} hooks []func() @@ -164,10 +168,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 { @@ -257,6 +261,7 @@ func init() { viper.SetDefault("lastfm.secret", consts.LastFMAPISecret) viper.SetDefault("spotify.id", "") viper.SetDefault("spotify.secret", "") + viper.SetDefault("listenbrainz.enabled", true) viper.SetDefault("ldap.host", "ldap://localhost:389") viper.SetDefault("ldap.binddn", "") @@ -277,7 +282,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 bb699a8a1..05b80be38 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 e2f8a5ca0..399dde1ee 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 6b04e62b3..00bd88eaa 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 965f26ae7..18ad34997 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 7bee5dbbe..86cea55c5 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 58a695cbe..60cff0a74 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) && ( )}