mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-28 00:24:19 +00:00
feat(panel): surface dev-build version in UI, bot, and CLI
A dev build now shows its `dev+<commit>` identity instead of a misleading stable-looking version in the sidebar badge, dashboard card, update modal, Telegram status report, startup log, and `x-ui -v`. Adds a shared formatPanelVersion helper (single v prefix; dev labels shown verbatim) and fixes the mobile-tag double-v. Renames the version getters for clarity: config.GetVersion to GetBaseVersion (raw embedded version), config.GetReportedVersion to GetPanelVersion (advertised/displayed), and the xray process GetVersion to GetXrayVersion.
This commit is contained in:
@@ -41,8 +41,11 @@ const (
|
||||
Error LogLevel = "error"
|
||||
)
|
||||
|
||||
// GetVersion returns the version string of the 3x-ui application.
|
||||
func GetVersion() string {
|
||||
// GetBaseVersion returns the raw embedded release version of the 3x-ui panel
|
||||
// (e.g. "3.4.0"). This is the panel's own version, not the Xray version. For the
|
||||
// version a panel advertises/displays (which adds a "dev+<sha>" label on dev
|
||||
// builds), use GetPanelVersion.
|
||||
func GetBaseVersion() string {
|
||||
return strings.TrimSpace(version)
|
||||
}
|
||||
|
||||
@@ -68,14 +71,14 @@ func IsDevBuild() bool {
|
||||
return GetBuildCommit() != ""
|
||||
}
|
||||
|
||||
// GetReportedVersion returns the version a panel advertises to a managing master
|
||||
// node: the plain version for stable builds, or "dev+<short commit>" for dev
|
||||
// builds. The dev form mirrors the master's getPanelUpdateInfo latestVersion so
|
||||
// a node on the current dev commit compares as up to date instead of always
|
||||
// showing "update available".
|
||||
func GetReportedVersion() string {
|
||||
// GetPanelVersion returns the version a panel advertises to a managing master
|
||||
// node and displays in the UI: the plain version for stable builds, or
|
||||
// "dev+<short commit>" for dev builds. The dev form mirrors the master's
|
||||
// getPanelUpdateInfo latestVersion so a node on the current dev commit compares
|
||||
// as up to date instead of always showing "update available".
|
||||
func GetPanelVersion() string {
|
||||
if !IsDevBuild() {
|
||||
return GetVersion()
|
||||
return GetBaseVersion()
|
||||
}
|
||||
commit := GetBuildCommit()
|
||||
if len(commit) > 8 {
|
||||
|
||||
@@ -5,23 +5,23 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetReportedVersion(t *testing.T) {
|
||||
func TestGetPanelVersion(t *testing.T) {
|
||||
orig := buildCommit
|
||||
t.Cleanup(func() { buildCommit = orig })
|
||||
|
||||
buildCommit = ""
|
||||
if got := GetReportedVersion(); got != GetVersion() {
|
||||
t.Fatalf("stable build: GetReportedVersion = %q, want %q", got, GetVersion())
|
||||
if got := GetPanelVersion(); got != GetBaseVersion() {
|
||||
t.Fatalf("stable build: GetPanelVersion = %q, want %q", got, GetBaseVersion())
|
||||
}
|
||||
|
||||
buildCommit = "1d1128cf"
|
||||
if got := GetReportedVersion(); got != "dev+1d1128cf" {
|
||||
t.Fatalf("dev build: GetReportedVersion = %q, want %q", got, "dev+1d1128cf")
|
||||
if got := GetPanelVersion(); got != "dev+1d1128cf" {
|
||||
t.Fatalf("dev build: GetPanelVersion = %q, want %q", got, "dev+1d1128cf")
|
||||
}
|
||||
|
||||
buildCommit = "1d1128cf945c4615efa05cf41ba7fa766e2ee428"
|
||||
if got := GetReportedVersion(); got != "dev+1d1128cf" {
|
||||
t.Fatalf("dev build (full sha): GetReportedVersion = %q, want %q", got, "dev+1d1128cf")
|
||||
if got := GetPanelVersion(); got != "dev+1d1128cf" {
|
||||
t.Fatalf("dev build (full sha): GetPanelVersion = %q, want %q", got, "dev+1d1128cf")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ func serveDistPage(c *gin.Context, name string) {
|
||||
}
|
||||
script := `<script` + nonceAttr + `>window.X_UI_BASE_PATH="` + escapedBase + `"`
|
||||
if name != "login.html" {
|
||||
escapedVer := jsEscape.Replace(config.GetVersion())
|
||||
escapedVer := jsEscape.Replace(config.GetPanelVersion())
|
||||
script += `;window.X_UI_CUR_VER="` + escapedVer + `"`
|
||||
script += `;window.X_UI_DB_TYPE="` + config.GetDBKind() + `"`
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ func (s *PanelService) GetUpdateInfo() (*PanelUpdateInfo, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
current := config.GetVersion()
|
||||
current := config.GetBaseVersion()
|
||||
return &PanelUpdateInfo{
|
||||
Channel: "stable",
|
||||
CurrentVersion: current,
|
||||
@@ -114,7 +114,7 @@ func getDevUpdateInfo() (*PanelUpdateInfo, error) {
|
||||
currentCommit := config.GetBuildCommit()
|
||||
return &PanelUpdateInfo{
|
||||
Channel: "dev",
|
||||
CurrentVersion: config.GetVersion(),
|
||||
CurrentVersion: config.GetPanelVersion(),
|
||||
CurrentCommit: shortCommit(currentCommit),
|
||||
LatestCommit: shortCommit(latestCommit),
|
||||
LatestVersion: "dev+" + shortCommit(latestCommit),
|
||||
|
||||
@@ -604,7 +604,7 @@ func (s *ServerService) GetStatus(lastStatus *Status) *Status {
|
||||
status.Xray.ErrorMsg = s.xrayService.GetXrayResult()
|
||||
}
|
||||
status.Xray.Version = s.xrayService.GetXrayVersion()
|
||||
status.PanelVersion = config.GetReportedVersion()
|
||||
status.PanelVersion = config.GetPanelVersion()
|
||||
if guid, err := s.settingService.GetPanelGuid(); err == nil {
|
||||
status.PanelGuid = guid
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ func (t *Tgbot) prepareServerUsageInfo() string {
|
||||
onlines := service.XrayProcess().GetOnlineClients()
|
||||
|
||||
info += t.I18nBot("tgbot.messages.hostname", "Hostname=="+hostname)
|
||||
info += t.I18nBot("tgbot.messages.version", "Version=="+config.GetVersion())
|
||||
info += t.I18nBot("tgbot.messages.version", "Version=="+config.GetPanelVersion())
|
||||
info += t.I18nBot("tgbot.messages.xrayVersion", "XrayVersion=="+fmt.Sprint(t.lastStatus.Xray.Version))
|
||||
|
||||
// get ip address
|
||||
|
||||
@@ -96,7 +96,7 @@ func (s *XrayService) GetXrayVersion() string {
|
||||
if p == nil {
|
||||
return "Unknown"
|
||||
}
|
||||
return p.GetVersion()
|
||||
return p.GetXrayVersion()
|
||||
}
|
||||
|
||||
// RemoveIndex removes an element at the specified index from a slice.
|
||||
|
||||
@@ -270,8 +270,8 @@ func (p *process) GetResult() string {
|
||||
return lastLine
|
||||
}
|
||||
|
||||
// GetVersion returns the version string of the Xray process.
|
||||
func (p *process) GetVersion() string {
|
||||
// GetXrayVersion returns the version string of the Xray process.
|
||||
func (p *process) GetXrayVersion() string {
|
||||
return p.version
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user