feat(remote): 显示控制中心和实例版本
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"douyu_go/internal/constants"
|
||||||
"douyu_go/internal/remote"
|
"douyu_go/internal/remote"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -37,12 +38,15 @@ func main() {
|
|||||||
OperatorToken: *operatorToken,
|
OperatorToken: *operatorToken,
|
||||||
EnrollToken: *enrollToken,
|
EnrollToken: *enrollToken,
|
||||||
EnrollWindow: *enrollWindow,
|
EnrollWindow: *enrollWindow,
|
||||||
|
Version: constants.Version,
|
||||||
|
BuildTime: constants.BuildTime,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
|
fmt.Printf("控制中心版本: %s (构建 %s)\n", constants.Version, constants.BuildTime)
|
||||||
fmt.Printf("远端控制台: http://%s/#admin=%s\n", displayAddr(*addr), *operatorToken)
|
fmt.Printf("远端控制台: http://%s/#admin=%s\n", displayAddr(*addr), *operatorToken)
|
||||||
if strings.TrimSpace(*enrollToken) != "" {
|
if strings.TrimSpace(*enrollToken) != "" {
|
||||||
fmt.Printf("实例注册需要注册令牌: %s\n", *enrollToken)
|
fmt.Printf("实例注册需要注册令牌: %s\n", *enrollToken)
|
||||||
|
|||||||
@@ -263,6 +263,8 @@ https://control.example.com
|
|||||||
### 机器与实例
|
### 机器与实例
|
||||||
|
|
||||||
- 按机器动态聚合并展示任意数量实例。
|
- 按机器动态聚合并展示任意数量实例。
|
||||||
|
- 页面顶栏显示控制中心版本,鼠标悬停可查看构建时间。
|
||||||
|
- 每个实例元信息显示桌面客户端版本,鼠标悬停可查看包含构建时间的完整版本。
|
||||||
- 显示在线状态、运行状态、账号数和当前结果数量。
|
- 显示在线状态、运行状态、账号数和当前结果数量。
|
||||||
- 点击“结果”展开当前账号结果。
|
- 点击“结果”展开当前账号结果。
|
||||||
- 点击“日志”只看该实例日志。
|
- 点击“日志”只看该实例日志。
|
||||||
@@ -464,11 +466,14 @@ GET /api/export?format=csv 能下载带 BOM 的日志
|
|||||||
GET /api/export?format=json 能下载结构化日志
|
GET /api/export?format=json 能下载结构化日志
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`/api/health` 无令牌可访问,返回控制中心 `version` 与 `buildTime`。`/api/dashboard` 必须携带管理令牌,并额外返回 `controlVersion` 与 `controlBuildTime`。
|
||||||
|
|
||||||
## 17. 变更记录
|
## 17. 变更记录
|
||||||
|
|
||||||
| 日期 | 变更 |
|
| 日期 | 变更 |
|
||||||
|---|---|
|
|---|---|
|
||||||
| 2026-11-21 | 建立远端控制、自动注册、动态机器聚合、实时日志、运行记录、主界面状态入口、CSV/JSON 导出 |
|
| 2026-11-21 | 建立远端控制、自动注册、动态机器聚合、实时日志、运行记录、主界面状态入口、CSV/JSON 导出 |
|
||||||
|
| 2026-11-22 | 控制台显示控制中心版本和实例客户端版本 |
|
||||||
| 2026-11-21 | 实例快照增加结构化代理状态,Web 控制台可查看代理组、出口和账号分组 |
|
| 2026-11-21 | 实例快照增加结构化代理状态,Web 控制台可查看代理组、出口和账号分组 |
|
||||||
| 2026-11-21 | 增加独立注册令牌配置和 `deploy/control-center` Docker/Caddy 部署目录 |
|
| 2026-11-21 | 增加独立注册令牌配置和 `deploy/control-center` Docker/Caddy 部署目录 |
|
||||||
| 2026-11-21 | 远端连接改为单行填写,并增加同机多实例自动继承 |
|
| 2026-11-21 | 远端连接改为单行填写,并增加同机多实例自动继承 |
|
||||||
|
|||||||
@@ -112,10 +112,12 @@ type ServerEvent struct {
|
|||||||
|
|
||||||
// DashboardState is the polling payload consumed by the remote web console.
|
// DashboardState is the polling payload consumed by the remote web console.
|
||||||
type DashboardState struct {
|
type DashboardState struct {
|
||||||
ServerTime time.Time `json:"serverTime"`
|
ServerTime time.Time `json:"serverTime"`
|
||||||
Instances []InstanceState `json:"instances"`
|
ControlVersion string `json:"controlVersion,omitempty"`
|
||||||
Runs []RunRecord `json:"runs"`
|
ControlBuildTime string `json:"controlBuildTime,omitempty"`
|
||||||
Commands []CommandAudit `json:"commands"`
|
Instances []InstanceState `json:"instances"`
|
||||||
|
Runs []RunRecord `json:"runs"`
|
||||||
|
Commands []CommandAudit `json:"commands"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandAudit records one command and its delivery/execution state.
|
// CommandAudit records one command and its delivery/execution state.
|
||||||
|
|||||||
@@ -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) {
|
func TestAgentAutoEnrollsWithoutManualToken(t *testing.T) {
|
||||||
server, err := NewServer(ServerOptions{
|
server, err := NewServer(ServerOptions{
|
||||||
DataDir: t.TempDir(),
|
DataDir: t.TempDir(),
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ type ServerOptions struct {
|
|||||||
OperatorToken string
|
OperatorToken string
|
||||||
EnrollToken string
|
EnrollToken string
|
||||||
EnrollWindow time.Duration
|
EnrollWindow time.Duration
|
||||||
|
Version string
|
||||||
|
BuildTime string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
@@ -57,6 +59,8 @@ func NewServer(opts ServerOptions) (*Server, error) {
|
|||||||
opts.AgentToken = strings.TrimSpace(opts.AgentToken)
|
opts.AgentToken = strings.TrimSpace(opts.AgentToken)
|
||||||
opts.OperatorToken = strings.TrimSpace(opts.OperatorToken)
|
opts.OperatorToken = strings.TrimSpace(opts.OperatorToken)
|
||||||
opts.EnrollToken = strings.TrimSpace(opts.EnrollToken)
|
opts.EnrollToken = strings.TrimSpace(opts.EnrollToken)
|
||||||
|
opts.Version = strings.TrimSpace(opts.Version)
|
||||||
|
opts.BuildTime = strings.TrimSpace(opts.BuildTime)
|
||||||
if opts.OperatorToken == "" {
|
if opts.OperatorToken == "" {
|
||||||
return nil, errors.New("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{
|
writeJSON(w, http.StatusOK, map[string]any{
|
||||||
"success": true,
|
"success": true,
|
||||||
"serverTime": time.Now(),
|
"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)
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||||
return
|
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) {
|
func (s *Server) handleEvents(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -21,6 +21,10 @@
|
|||||||
}
|
}
|
||||||
header h1 { font-size: 16px; margin: 0; white-space: nowrap; }
|
header h1 { font-size: 16px; margin: 0; white-space: nowrap; }
|
||||||
.muted { color: #8f9baa; }
|
.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; }
|
.grow { flex: 1; }
|
||||||
.token-box { display: flex; gap: 8px; align-items: center; }
|
.token-box { display: flex; gap: 8px; align-items: center; }
|
||||||
input {
|
input {
|
||||||
@@ -132,6 +136,7 @@
|
|||||||
<div class="shell">
|
<div class="shell">
|
||||||
<header>
|
<header>
|
||||||
<h1>斗鱼抢购远端控制台</h1>
|
<h1>斗鱼抢购远端控制台</h1>
|
||||||
|
<span id="control-version" class="version-pill">控制中心版本加载中</span>
|
||||||
<span id="connection" class="muted">未连接</span>
|
<span id="connection" class="muted">未连接</span>
|
||||||
<div class="grow"></div>
|
<div class="grow"></div>
|
||||||
<div class="token-box">
|
<div class="token-box">
|
||||||
@@ -170,6 +175,7 @@
|
|||||||
const tokenInput = document.getElementById('token');
|
const tokenInput = document.getElementById('token');
|
||||||
const connectButton = document.getElementById('connect');
|
const connectButton = document.getElementById('connect');
|
||||||
const connection = document.getElementById('connection');
|
const connection = document.getElementById('connection');
|
||||||
|
const controlVersion = document.getElementById('control-version');
|
||||||
const machinesRoot = document.getElementById('machines');
|
const machinesRoot = document.getElementById('machines');
|
||||||
const runsRoot = document.getElementById('runs');
|
const runsRoot = document.getElementById('runs');
|
||||||
const summary = document.getElementById('summary');
|
const summary = document.getElementById('summary');
|
||||||
@@ -301,6 +307,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderDashboard(data) {
|
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();
|
const groups = new Map();
|
||||||
for (const item of data.instances || []) {
|
for (const item of data.instances || []) {
|
||||||
const key = item.machineId || item.machineName;
|
const key = item.machineId || item.machineName;
|
||||||
@@ -359,7 +370,10 @@
|
|||||||
? `代理 ${proxy.activeCount || 0} · 备用 ${proxy.standbyCount || 0}/${proxy.standbyTarget || 0} · 直连 ${proxy.directCount || 0}`
|
? `代理 ${proxy.activeCount || 0} · 备用 ${proxy.standbyCount || 0}/${proxy.standbyTarget || 0} · 直连 ${proxy.directCount || 0}`
|
||||||
: '本地直连';
|
: '本地直连';
|
||||||
const proxyWarning = ['direct_fallback', 'failed', 'degraded'].includes(proxy?.state);
|
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');
|
const actions = element('div', 'actions');
|
||||||
actions.append(
|
actions.append(
|
||||||
|
|||||||
Reference in New Issue
Block a user