Skip to content

🎧 Your Personal Streaming Service

Pass version to UI through AppConfig, instead of login payload.master

Deluan089a92157f62
diff --git a/server/app/auth.go b/server/app/auth.go
index d2f2b3baa..534f44910 100644
--- a/server/app/auth.go
+++ b/server/app/auth.go
@@ -63,7 +63,6 @@ func handleLogin(ds model.DataStore, username string, password string, w http.Re
"name": user.Name,
"username": username,
"isAdmin": user.IsAdmin,
- "version": consts.Version(),
})
}
diff --git a/server/app/serve_index.go b/server/app/serve_index.go
index 56f1666cc..2086ef798 100644
--- a/server/app/serve_index.go
+++ b/server/app/serve_index.go
@@ -19,22 +19,16 @@ func ServeIndex(ds model.DataStore, fs http.FileSystem) http.HandlerFunc {
c, err := ds.User(r.Context()).CountAll()
firstTime := c == 0 && err == nil
- t := template.New("initial state")
- indexHtml, err := fs.Open("index.html")
- if err != nil {
- log.Error(r, "Could not find `index.html` template", err)
- }
- indexStr, err := ioutil.ReadAll(indexHtml)
- if err != nil {
- log.Error(r, "Could not read from `index.html`", err)
- }
- t, _ = t.Parse(string(indexStr))
+ t := getIndexTemplate(r, fs)
+
appConfig := map[string]interface{}{
+ "version": consts.Version(),
"firstTime": firstTime,
"baseURL": strings.TrimSuffix(conf.Server.BaseURL, "/"),
"loginBackgroundURL": conf.Server.UILoginBackgroundURL,
}
j, _ := json.Marshal(appConfig)
+
data := map[string]interface{}{
"AppConfig": string(j),
"Version": consts.Version(),
@@ -45,3 +39,20 @@ func ServeIndex(ds model.DataStore, fs http.FileSystem) http.HandlerFunc {
}
}
}
+
+func getIndexTemplate(r *http.Request, fs http.FileSystem) *template.Template {
+ t := template.New("initial state")
+ indexHtml, err := fs.Open("index.html")
+ if err != nil {
+ log.Error(r, "Could not find `index.html` template", err)
+ }
+ indexStr, err := ioutil.ReadAll(indexHtml)
+ if err != nil {
+ log.Error(r, "Could not read from `index.html`", err)
+ }
+ t, err = t.Parse(string(indexStr))
+ if err != nil {
+ log.Error(r, "Error parsing `index.html`", err)
+ }
+ return t
+}
diff --git a/server/app/serve_index_test.go b/server/app/serve_index_test.go
index bf68b000a..db6c8f125 100644
--- a/server/app/serve_index_test.go
+++ b/server/app/serve_index_test.go
@@ -9,6 +9,7 @@ import (
"strconv"
"github.com/deluan/navidrome/conf"
+ "github.com/deluan/navidrome/consts"
"github.com/deluan/navidrome/model"
"github.com/deluan/navidrome/persistence"
. "github.com/onsi/ginkgo"
@@ -79,6 +80,16 @@ var _ = Describe("ServeIndex", func() {
config := extractAppConfig(w.Body.String())
Expect(config).To(HaveKeyWithValue("loginBackgroundURL", "my_background_url"))
})
+
+ It("sets the version", func() {
+ r := httptest.NewRequest("GET", "/index.html", nil)
+ w := httptest.NewRecorder()
+
+ ServeIndex(ds, fs)(w, r)
+
+ config := extractAppConfig(w.Body.String())
+ Expect(config).To(HaveKeyWithValue("version", consts.Version()))
+ })
})
var appConfigRegex = regexp.MustCompile(`(?m)window.__APP_CONFIG__="([^"]*)`)
diff --git a/ui/src/authProvider.js b/ui/src/authProvider.js
index 58e68bb32..58ff2ea6a 100644
--- a/ui/src/authProvider.js
+++ b/ui/src/authProvider.js
@@ -26,7 +26,6 @@ const authProvider = {
jwtDecode(response.token)
localStorage.removeItem('initialAccountCreation')
localStorage.setItem('token', response.token)
- localStorage.setItem('version', response.version)
localStorage.setItem('name', response.name)
localStorage.setItem('username', response.username)
localStorage.setItem('role', response.isAdmin ? 'admin' : 'regular')
@@ -77,7 +76,6 @@ const removeItems = () => {
localStorage.removeItem('name')
localStorage.removeItem('username')
localStorage.removeItem('role')
- localStorage.removeItem('version')
localStorage.removeItem('subsonic-salt')
localStorage.removeItem('subsonic-token')
}
diff --git a/ui/src/config.js b/ui/src/config.js
index 01de2b2d2..634217219 100644
--- a/ui/src/config.js
+++ b/ui/src/config.js
@@ -1,4 +1,5 @@
const defaultConfig = {
+ version: 'dev',
firstTime: false,
baseURL: '',
loginBackgroundURL: 'https://source.unsplash.com/random/1600x900?music'
diff --git a/ui/src/layout/AppBar.js b/ui/src/layout/AppBar.js
index 468fccc99..92ffb117c 100644
--- a/ui/src/layout/AppBar.js
+++ b/ui/src/layout/AppBar.js
@@ -7,6 +7,7 @@ import {
} from 'react-admin'
import { makeStyles } from '@material-ui/core'
import InfoIcon from '@material-ui/icons/Info'
+import config from '../config'
const useStyles = makeStyles((theme) => ({
menuItem: {
@@ -22,7 +23,7 @@ const VersionMenu = forwardRef((props, ref) => {
ref={ref}
to="#"
primaryText={translate('menu.version', {
- version: localStorage.getItem('version')
+ version: config.version
})}
leftIcon={<InfoIcon />}
className={classes.menuItem}