From 9ed41d6551f08e03c93f9d10d9444c7588f8dc9b Mon Sep 17 00:00:00 2001 From: yml Date: Sun, 22 Nov 2026 15:26:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(remote):=20=E6=98=BE=E7=A4=BA=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E4=B8=AD=E5=BF=83=E5=92=8C=E5=AE=9E=E4=BE=8B=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/douyu-control/main.go | 4 +++ docs/远程控制.md | 5 ++++ internal/remote/protocol.go | 10 +++++--- internal/remote/remote_test.go | 46 ++++++++++++++++++++++++++++++++++ internal/remote/server.go | 11 +++++++- internal/remote/web/index.html | 16 +++++++++++- 6 files changed, 86 insertions(+), 6 deletions(-) diff --git a/cmd/douyu-control/main.go b/cmd/douyu-control/main.go index c649b28..edfd2b8 100644 --- a/cmd/douyu-control/main.go +++ b/cmd/douyu-control/main.go @@ -10,6 +10,7 @@ import ( "syscall" "time" + "douyu_go/internal/constants" "douyu_go/internal/remote" ) @@ -37,12 +38,15 @@ func main() { OperatorToken: *operatorToken, EnrollToken: *enrollToken, EnrollWindow: *enrollWindow, + Version: constants.Version, + BuildTime: constants.BuildTime, }) if err != nil { log.Fatal(err) } defer server.Close() + fmt.Printf("控制中心版本: %s (构建 %s)\n", constants.Version, constants.BuildTime) fmt.Printf("远端控制台: http://%s/#admin=%s\n", displayAddr(*addr), *operatorToken) if strings.TrimSpace(*enrollToken) != "" { fmt.Printf("实例注册需要注册令牌: %s\n", *enrollToken) diff --git a/docs/远程控制.md b/docs/远程控制.md index aee1842..8c81db4 100644 --- a/docs/远程控制.md +++ b/docs/远程控制.md @@ -263,6 +263,8 @@ https://control.example.com ### 机器与实例 - 按机器动态聚合并展示任意数量实例。 +- 页面顶栏显示控制中心版本,鼠标悬停可查看构建时间。 +- 每个实例元信息显示桌面客户端版本,鼠标悬停可查看包含构建时间的完整版本。 - 显示在线状态、运行状态、账号数和当前结果数量。 - 点击“结果”展开当前账号结果。 - 点击“日志”只看该实例日志。 @@ -464,11 +466,14 @@ GET /api/export?format=csv 能下载带 BOM 的日志 GET /api/export?format=json 能下载结构化日志 ``` +`/api/health` 无令牌可访问,返回控制中心 `version` 与 `buildTime`。`/api/dashboard` 必须携带管理令牌,并额外返回 `controlVersion` 与 `controlBuildTime`。 + ## 17. 变更记录 | 日期 | 变更 | |---|---| | 2026-11-21 | 建立远端控制、自动注册、动态机器聚合、实时日志、运行记录、主界面状态入口、CSV/JSON 导出 | +| 2026-11-22 | 控制台显示控制中心版本和实例客户端版本 | | 2026-11-21 | 实例快照增加结构化代理状态,Web 控制台可查看代理组、出口和账号分组 | | 2026-11-21 | 增加独立注册令牌配置和 `deploy/control-center` Docker/Caddy 部署目录 | | 2026-11-21 | 远端连接改为单行填写,并增加同机多实例自动继承 | diff --git a/internal/remote/protocol.go b/internal/remote/protocol.go index d06dcea..4f7460a 100644 --- a/internal/remote/protocol.go +++ b/internal/remote/protocol.go @@ -112,10 +112,12 @@ type ServerEvent struct { // DashboardState is the polling payload consumed by the remote web console. type DashboardState struct { - ServerTime time.Time `json:"serverTime"` - Instances []InstanceState `json:"instances"` - Runs []RunRecord `json:"runs"` - Commands []CommandAudit `json:"commands"` + ServerTime time.Time `json:"serverTime"` + ControlVersion string `json:"controlVersion,omitempty"` + ControlBuildTime string `json:"controlBuildTime,omitempty"` + Instances []InstanceState `json:"instances"` + Runs []RunRecord `json:"runs"` + Commands []CommandAudit `json:"commands"` } // CommandAudit records one command and its delivery/execution state. diff --git a/internal/remote/remote_test.go b/internal/remote/remote_test.go index 31f6f58..5ba9931 100644 --- a/internal/remote/remote_test.go +++ b/internal/remote/remote_test.go @@ -191,6 +191,52 @@ func TestDashboardRequiresOperatorToken(t *testing.T) { } } +func TestHealthAndDashboardExposeControlVersion(t *testing.T) { + server, err := NewServer(ServerOptions{ + DataDir: t.TempDir(), + OperatorToken: "operator", + Version: "0.6.4", + BuildTime: "2026-11-22 16:00:00", + }) + if err != nil { + t.Fatal(err) + } + defer server.Close() + httpServer := httptest.NewServer(server.Handler()) + defer httpServer.Close() + + healthResponse, err := http.Get(httpServer.URL + "/api/health") + if err != nil { + t.Fatal(err) + } + defer healthResponse.Body.Close() + var health map[string]any + if err := json.NewDecoder(healthResponse.Body).Decode(&health); err != nil { + t.Fatal(err) + } + if health["version"] != "0.6.4" || health["buildTime"] != "2026-11-22 16:00:00" { + t.Fatalf("unexpected health version payload: %#v", health) + } + + request, err := http.NewRequest(http.MethodGet, httpServer.URL+"/api/dashboard", nil) + if err != nil { + t.Fatal(err) + } + request.Header.Set("X-Control-Token", "operator") + dashboardResponse, err := http.DefaultClient.Do(request) + if err != nil { + t.Fatal(err) + } + defer dashboardResponse.Body.Close() + var dashboard DashboardState + if err := json.NewDecoder(dashboardResponse.Body).Decode(&dashboard); err != nil { + t.Fatal(err) + } + if dashboard.ControlVersion != "0.6.4" || dashboard.ControlBuildTime != "2026-11-22 16:00:00" { + t.Fatalf("unexpected dashboard version payload: %+v", dashboard) + } +} + func TestAgentAutoEnrollsWithoutManualToken(t *testing.T) { server, err := NewServer(ServerOptions{ DataDir: t.TempDir(), diff --git a/internal/remote/server.go b/internal/remote/server.go index e996fd8..95396bc 100644 --- a/internal/remote/server.go +++ b/internal/remote/server.go @@ -26,6 +26,8 @@ type ServerOptions struct { OperatorToken string EnrollToken string EnrollWindow time.Duration + Version string + BuildTime string } type Server struct { @@ -57,6 +59,8 @@ func NewServer(opts ServerOptions) (*Server, error) { opts.AgentToken = strings.TrimSpace(opts.AgentToken) opts.OperatorToken = strings.TrimSpace(opts.OperatorToken) opts.EnrollToken = strings.TrimSpace(opts.EnrollToken) + opts.Version = strings.TrimSpace(opts.Version) + opts.BuildTime = strings.TrimSpace(opts.BuildTime) if opts.OperatorToken == "" { return nil, errors.New("OperatorToken 不能为空") } @@ -221,6 +225,8 @@ func (s *Server) handleHealth(w http.ResponseWriter, _ *http.Request) { writeJSON(w, http.StatusOK, map[string]any{ "success": true, "serverTime": time.Now(), + "version": s.opts.Version, + "buildTime": s.opts.BuildTime, }) } @@ -232,7 +238,10 @@ func (s *Server) handleDashboard(w http.ResponseWriter, r *http.Request) { http.Error(w, "method not allowed", http.StatusMethodNotAllowed) return } - writeJSON(w, http.StatusOK, s.hub.Dashboard()) + dashboard := s.hub.Dashboard() + dashboard.ControlVersion = s.opts.Version + dashboard.ControlBuildTime = s.opts.BuildTime + writeJSON(w, http.StatusOK, dashboard) } func (s *Server) handleEvents(w http.ResponseWriter, r *http.Request) { diff --git a/internal/remote/web/index.html b/internal/remote/web/index.html index eff63a1..909ff1a 100644 --- a/internal/remote/web/index.html +++ b/internal/remote/web/index.html @@ -21,6 +21,10 @@ } header h1 { font-size: 16px; margin: 0; white-space: nowrap; } .muted { color: #8f9baa; } + .version-pill { + padding: 4px 8px; border: 1px solid #35404c; border-radius: 999px; + color: #9dabba; font-size: 11px; white-space: nowrap; + } .grow { flex: 1; } .token-box { display: flex; gap: 8px; align-items: center; } input { @@ -132,6 +136,7 @@

斗鱼抢购远端控制台

+ 控制中心版本加载中 未连接
@@ -170,6 +175,7 @@ const tokenInput = document.getElementById('token'); const connectButton = document.getElementById('connect'); const connection = document.getElementById('connection'); + const controlVersion = document.getElementById('control-version'); const machinesRoot = document.getElementById('machines'); const runsRoot = document.getElementById('runs'); const summary = document.getElementById('summary'); @@ -301,6 +307,11 @@ } function renderDashboard(data) { + const controlVersionText = String(data.controlVersion || '').split(' ')[0].replace(/^v/, ''); + controlVersion.textContent = controlVersionText + ? `控制中心 v${controlVersionText}` + : '控制中心版本未知'; + controlVersion.title = data.controlBuildTime ? `构建时间: ${data.controlBuildTime}` : ''; const groups = new Map(); for (const item of data.instances || []) { const key = item.machineId || item.machineName; @@ -359,7 +370,10 @@ ? `代理 ${proxy.activeCount || 0} · 备用 ${proxy.standbyCount || 0}/${proxy.standbyTarget || 0} · 直连 ${proxy.directCount || 0}` : '本地直连'; const proxyWarning = ['direct_fallback', 'failed', 'degraded'].includes(proxy?.state); - const meta = textNode('div', `${item.accountCount || 0} 账号 · ${proxyText}`, proxyWarning ? 'bad' : 'muted'); + const instanceVersion = String(item.version || '').split(' ')[0].replace(/^v/, ''); + const versionText = instanceVersion ? ` · v${instanceVersion}` : ''; + const meta = textNode('div', `${item.accountCount || 0} 账号 · ${proxyText}${versionText}`, proxyWarning ? 'bad' : 'muted'); + meta.title = item.version ? `实例版本: ${item.version}` : ''; const actions = element('div', 'actions'); actions.append(