feat(client, server): add client name handling and machine ID retrieval
Some checks failed
Build Multi-Platform Binaries / build-binaries (amd64, darwin, server, false) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, linux, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, linux, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, windows, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, windows, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, darwin, server, false) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, linux, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, linux, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, windows, server, false) (push) Has been cancelled
Build Multi-Platform Binaries / build-frontend (push) Has been cancelled

This commit is contained in:
Flik
2026-01-27 08:56:05 +08:00
parent 3386b0fcb6
commit 0a41e10793
13 changed files with 196 additions and 55 deletions

View File

@@ -115,7 +115,7 @@ func (h *ClientHandler) Get(c *gin.Context) {
return
}
online, lastPing, remoteAddr, clientOS, clientArch, clientVersion := h.app.GetServer().GetClientStatus(clientID)
online, lastPing, remoteAddr, clientName, clientOS, clientArch, clientVersion := h.app.GetServer().GetClientStatus(clientID)
// 复制插件列表
plugins := make([]db.ClientPlugin, len(client.Plugins))
@@ -145,9 +145,15 @@ func (h *ClientHandler) Get(c *gin.Context) {
}
}
// 如果客户端在线且有名称,优先使用在线名称
nickname := client.Nickname
if online && clientName != "" && nickname == "" {
nickname = clientName
}
resp := dto.ClientResponse{
ID: client.ID,
Nickname: client.Nickname,
Nickname: nickname,
Rules: client.Rules,
Plugins: plugins,
Online: online,
@@ -242,8 +248,7 @@ func (h *ClientHandler) Delete(c *gin.Context) {
func (h *ClientHandler) PushConfig(c *gin.Context) {
clientID := c.Param("id")
online, _, _, _, _, _ := h.app.GetServer().GetClientStatus(clientID)
if !online {
if !h.app.GetServer().IsClientOnline(clientID) {
ClientNotOnline(c)
return
}
@@ -311,8 +316,7 @@ func (h *ClientHandler) Restart(c *gin.Context) {
func (h *ClientHandler) InstallPlugins(c *gin.Context) {
clientID := c.Param("id")
online, _, _, _, _, _ := h.app.GetServer().GetClientStatus(clientID)
if !online {
if !h.app.GetServer().IsClientOnline(clientID) {
ClientNotOnline(c)
return
}

View File

@@ -19,11 +19,13 @@ type AppInterface interface {
// ServerInterface 服务端接口
type ServerInterface interface {
GetClientStatus(clientID string) (online bool, lastPing, remoteAddr, clientOS, clientArch, clientVersion string)
IsClientOnline(clientID string) bool
GetClientStatus(clientID string) (online bool, lastPing, remoteAddr, clientName, clientOS, clientArch, clientVersion string)
GetAllClientStatus() map[string]struct {
Online bool
LastPing string
RemoteAddr string
Name string
OS string
Arch string
Version string

View File

@@ -177,8 +177,7 @@ func (h *JSPluginHandler) PushToClient(c *gin.Context) {
c.ShouldBindJSON(&pushReq) // 忽略错误,允许空请求体
// 检查客户端是否在线
online, _, _, _, _, _ := h.app.GetServer().GetClientStatus(clientID)
if !online {
if !h.app.GetServer().IsClientOnline(clientID) {
ClientNotOnline(c)
return
}

View File

@@ -35,8 +35,7 @@ func (h *LogHandler) StreamLogs(c *gin.Context) {
clientID := c.Param("id")
// 检查客户端是否在线
online, _, _, _, _, _ := h.app.GetServer().GetClientStatus(clientID)
if !online {
if !h.app.GetServer().IsClientOnline(clientID) {
c.JSON(400, gin.H{"code": 400, "message": "client not online"})
return
}

View File

@@ -371,8 +371,7 @@ func (h *PluginHandler) UpdateClientConfig(c *gin.Context) {
}
// 如果客户端在线,同步配置
online, _, _, _, _, _ := h.app.GetServer().GetClientStatus(clientID)
if online {
if h.app.GetServer().IsClientOnline(clientID) {
if err := h.app.GetServer().SyncPluginConfigToClient(clientID, pluginName, req.Config); err != nil {
PartialSuccess(c, gin.H{"status": "partial", "port_changed": portChanged}, "config saved but sync failed: "+err.Error())
return

View File

@@ -45,8 +45,7 @@ func (h *PluginAPIHandler) ProxyRequest(c *gin.Context) {
}
// 检查客户端是否在线
online, _, _, _, _, _ := h.app.GetServer().GetClientStatus(clientID)
if !online {
if !h.app.GetServer().IsClientOnline(clientID) {
ClientNotOnline(c)
return
}

View File

@@ -82,8 +82,7 @@ func (h *StoreHandler) Install(c *gin.Context) {
}
// 检查客户端是否在线
online, _, _, _, _, _ := h.app.GetServer().GetClientStatus(req.ClientID)
if !online {
if !h.app.GetServer().IsClientOnline(req.ClientID) {
ClientNotOnline(c)
return
}