mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-24 14:47:23 +00:00
Enhance version-info (#170)
This commit is contained in:
@@ -34,10 +34,15 @@ var (
|
||||
version = "dev"
|
||||
commit = "unknown"
|
||||
date = "unknown"
|
||||
repoURL = "https://github.com/gesellix/bose-soundtouch"
|
||||
)
|
||||
|
||||
func updateBuildInfo() {
|
||||
if info, ok := debug.ReadBuildInfo(); ok {
|
||||
if info.Main.Path != "" {
|
||||
repoURL = "https://" + info.Main.Path
|
||||
}
|
||||
|
||||
if info.Main.Version != "" && info.Main.Version != "(devel)" {
|
||||
version = info.Main.Version
|
||||
}
|
||||
@@ -48,7 +53,7 @@ func updateBuildInfo() {
|
||||
commit = setting.Value
|
||||
case "vcs.time":
|
||||
if t, err := time.Parse(time.RFC3339, setting.Value); err == nil {
|
||||
date = t.Format("2006-01-02_15:04:05")
|
||||
date = t.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -300,7 +305,7 @@ func main() {
|
||||
server := handlers.NewServer(ds, sm, config.serverURL, config.redact, config.logBody, config.record)
|
||||
sm.GetDNSRunning = server.GetDNSRunning
|
||||
server.SetHTTPServerURL(config.httpsServerURL)
|
||||
server.SetVersionInfo(version, commit, date)
|
||||
server.SetVersionInfo(version, commit, date, repoURL)
|
||||
server.SetDiscoverySettings(config.discoveryInterval, persisted.DiscoveryEnabled)
|
||||
server.SetDNSSettings(persisted.DNSEnabled, strings.Join(persisted.DNSUpstream, ","), persisted.DNSBindAddr)
|
||||
server.SetMirrorSettings(persisted.MirrorEnabled, persisted.MirrorEndpoints, persisted.SkipMirrorEndpoints, persisted.PreferredSource)
|
||||
|
||||
@@ -1084,14 +1084,36 @@ func (s *Server) HandleTestConnection(w http.ResponseWriter, r *http.Request) {
|
||||
// HandleGetVersionInfo returns version information for the service.
|
||||
func (s *Server) HandleGetVersionInfo(w http.ResponseWriter, _ *http.Request) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
version := s.Version
|
||||
commit := s.Commit
|
||||
date := s.Date
|
||||
repoURL := s.RepoURL
|
||||
s.mu.RUnlock()
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
var (
|
||||
releaseURL string
|
||||
commitURL string
|
||||
)
|
||||
|
||||
if commit != "" && commit != "unknown" {
|
||||
commitURL = fmt.Sprintf("%s/commit/%s", repoURL, commit)
|
||||
}
|
||||
|
||||
// Release version: should point to the release, e.g. https://github.com/gesellix/Bose-SoundTouch/releases/tag/v0.58.0
|
||||
// "dirty" versions don't get a release link (only the commit).
|
||||
if version != "" && version != "dev" && version != "(devel)" && !strings.Contains(version, "dirty") {
|
||||
releaseURL = fmt.Sprintf("%s/releases/tag/%s", repoURL, version)
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(map[string]string{
|
||||
"version": s.Version,
|
||||
"commit": s.Commit,
|
||||
"date": s.Date,
|
||||
"version": version,
|
||||
"commit": commit,
|
||||
"date": date,
|
||||
"repo_url": repoURL,
|
||||
"release_url": releaseURL,
|
||||
"commit_url": commitURL,
|
||||
}); err != nil {
|
||||
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -50,6 +50,7 @@ type Server struct {
|
||||
Version string
|
||||
Commit string
|
||||
Date string
|
||||
RepoURL string
|
||||
mgmtUsername string
|
||||
mgmtPassword string
|
||||
spotifyClientID string
|
||||
@@ -96,13 +97,14 @@ func NewServer(ds *datastore.DataStore, sm *setup.Manager, serverURL string, pro
|
||||
}
|
||||
|
||||
// SetVersionInfo sets the version information for the server.
|
||||
func (s *Server) SetVersionInfo(version, commit, date string) {
|
||||
func (s *Server) SetVersionInfo(version, commit, date, repoURL string) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
s.Version = version
|
||||
s.Commit = commit
|
||||
s.Date = date
|
||||
s.RepoURL = repoURL
|
||||
}
|
||||
|
||||
// SetDiscoverySettings sets the discovery settings for the server.
|
||||
|
||||
@@ -464,7 +464,16 @@ async function fetchVersion() {
|
||||
const data = await response.json();
|
||||
const info = document.getElementById("version-info");
|
||||
if (info && data.version) {
|
||||
info.innerText = `AfterTouch ${data.version} (${data.commit}) - ${data.date}`;
|
||||
let versionStr = data.version;
|
||||
if (data.release_url) {
|
||||
versionStr = `<a href="${data.release_url}" target="_blank" style="color: inherit; text-decoration: underline;">${data.version}</a>`;
|
||||
}
|
||||
let commitStr = data.commit;
|
||||
if (data.commit_url) {
|
||||
const shortCommit = data.commit.substring(0, 7);
|
||||
commitStr = `<a href="${data.commit_url}" target="_blank" style="color: inherit; text-decoration: underline;">${shortCommit}</a>`;
|
||||
}
|
||||
info.innerHTML = `AfterTouch ${versionStr} (${commitStr}) - ${data.date}`;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch version info", error);
|
||||
|
||||
Reference in New Issue
Block a user