feat: DevTools综合升级 — 记忆查询 + 会话监看 + WebUI侧边栏重构
- docs: 17个文件重命名为 YYYY-MM-DD.HH-mm-SS-内容.md 格式 - config: 管理员凭据移至 backend/.env (ADMIN_USERNAME/PASSWORD) - gateway: 新增 SessionState 会话追踪 + GET /api/v1/admin/sessions - devtools: 新增7个代理端点 (dashboard/sessions/memory) - devtools: WebUI重构为侧边栏 + 5面板 (仪表盘/记忆/会话/服务/性能)
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/yourname/cyrene-ai/gateway/internal/config"
|
||||
@@ -16,7 +19,7 @@ func Setup(r *gin.Engine, hub *ws.Hub, cfg *config.Config) {
|
||||
|
||||
// 初始化处理器
|
||||
authHandler := handler.NewAuthHandler(cfg)
|
||||
sessionHandler := handler.NewSessionHandler()
|
||||
sessionHandler := handler.NewSessionHandler(hub)
|
||||
memoryHandler := handler.NewMemoryHandler(cfg.AICoreURL)
|
||||
chatHandler := handler.NewChatHandler(cfg, hub)
|
||||
|
||||
@@ -63,6 +66,14 @@ func Setup(r *gin.Engine, hub *ws.Hub, cfg *config.Config) {
|
||||
memory.GET("", memoryHandler.List)
|
||||
memory.POST("", memoryHandler.Add)
|
||||
}
|
||||
|
||||
// Admin 路由 (需要管理员权限)
|
||||
admin := protected.Group("/admin")
|
||||
admin.Use(adminAuth())
|
||||
{
|
||||
admin.GET("/sessions", sessionHandler.ListActiveSessions)
|
||||
admin.GET("/sessions/:id", sessionHandler.GetSession)
|
||||
}
|
||||
}
|
||||
|
||||
// ========== WebSocket路由 ==========
|
||||
@@ -81,3 +92,16 @@ func Setup(r *gin.Engine, hub *ws.Hub, cfg *config.Config) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// adminAuth 管理员权限中间件 (检查 userID 是否以 "admin_" 开头)
|
||||
func adminAuth() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
userID := middleware.GetUserID(c)
|
||||
if userID == "" || !strings.HasPrefix(userID, "admin_") {
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": "需要管理员权限"})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user