Only compute version once

This commit is contained in:
Deluan 2022-09-14 21:09:39 -04:00
parent ebad96b8a4
commit 4cf43ed735
8 changed files with 20 additions and 10 deletions

View File

@ -32,7 +32,7 @@ Complete documentation is available at https://www.navidrome.org/docs`,
Run: func(cmd *cobra.Command, args []string) {
runNavidrome()
},
Version: consts.Version(),
Version: consts.Version,
}
)

View File

@ -11,15 +11,16 @@ var (
gitSha string
)
// Formats:
// Version holds the version string, with tag and git sha info.
// Examples:
// dev
// v0.2.0 (5b84188)
// v0.3.2-SNAPSHOT (715f552)
// master (9ed35cb)
func Version() string {
var Version = func() string {
if gitSha == "" {
return "dev"
}
gitTag = strings.TrimPrefix(gitTag, "v")
return fmt.Sprintf("%s (%s)", gitTag, gitSha)
}
}()

View File

@ -1,11 +1,20 @@
package model
import (
"io/fs"
"os"
)
type MediaFolder struct {
ID int32
Name string
Path string
}
func (f MediaFolder) FS() fs.FS {
return os.DirFS(f.Path)
}
type MediaFolders []MediaFolder
type MediaFolderRepository interface {

View File

@ -14,6 +14,6 @@ func loadBanner() string {
}
func Banner() string {
version := "Version: " + consts.Version()
version := "Version: " + consts.Version
return fmt.Sprintf("%s\n%52s\n", loadBanner(), version)
}

View File

@ -212,7 +212,7 @@ func (b *broker) listen() {
// Send a serverStart event to new client
msg := b.prepareMessage(context.Background(),
&ServerStart{StartTime: consts.ServerStart, Version: consts.Version()})
&ServerStart{StartTime: consts.ServerStart, Version: consts.Version})
c.diode.put(msg)
case c := <-b.unsubscribing:

View File

@ -27,7 +27,7 @@ func serveIndex(ds model.DataStore, fs fs.FS) http.HandlerFunc {
return
}
appConfig := map[string]interface{}{
"version": consts.Version(),
"version": consts.Version,
"firstTime": firstTime,
"variousArtistsId": consts.VariousArtistsID,
"baseURL": utils.SanitizeText(strings.TrimSuffix(conf.Server.BaseURL, "/")),
@ -63,7 +63,7 @@ func serveIndex(ds model.DataStore, fs fs.FS) http.HandlerFunc {
}
log.Debug("UI configuration", "appConfig", appConfig)
version := consts.Version()
version := consts.Version
if version != "dev" {
version = "v" + version
}

View File

@ -188,7 +188,7 @@ var _ = Describe("serveIndex", func() {
serveIndex(ds, fs)(w, r)
config := extractAppConfig(w.Body.String())
Expect(config).To(HaveKeyWithValue("version", consts.Version()))
Expect(config).To(HaveKeyWithValue("version", consts.Version))
})
It("sets the losslessFormats", func() {

View File

@ -15,7 +15,7 @@ import (
)
func newResponse() *responses.Subsonic {
return &responses.Subsonic{Status: "ok", Version: Version, Type: consts.AppName, ServerVersion: consts.Version()}
return &responses.Subsonic{Status: "ok", Version: Version, Type: consts.AppName, ServerVersion: consts.Version}
}
func requiredParamString(r *http.Request, param string) (string, error) {