fix: agent tasks cmd

This commit is contained in:
engigu
2025-12-30 21:09:36 +08:00
parent 7f83401b2e
commit 94c6e1b7fb
3 changed files with 24 additions and 0 deletions
+14
View File
@@ -207,7 +207,21 @@ func (c *AgentController) GetTasks(ctx *gin.Context) {
return
}
// 先尝试通过 token 查找 Agent
agent := c.agentService.GetByToken(token)
// 如果找不到,尝试验证令牌并通过 machine_id 查找
if agent == nil {
machineID := ctx.GetHeader("X-Machine-ID")
if machineID != "" {
// 验证令牌是否有效
if _, err := c.agentService.ValidateToken(token); err == nil {
// 令牌有效,尝试通过 machine_id 查找 Agent
agent = c.agentService.GetByMachineID(machineID)
}
}
}
if agent == nil {
utils.Unauthorized(ctx, "无效的 Token")
return