feat(audit): F1+F2 告警静默规则标记完成 + 审计日志CSV导出实现
F1 告警静默规则 [done]: - 后端 alert_silence.go: CRUD + Toggle (onetime/daily/weekly 三模式) - 告警引擎 isSilenced 集成 (alert_engine.go) - 前端 SilenceRuleTab + SilenceDialog - 路由 /alerts/silences 已注册 F2 审计日志导出 [done]: - 重写 ExportAuditLogs: 真正的 CSV 导出 (encoding/csv + UTF-8 BOM) - 支持 module/action/username/startTime/endTime 筛选 - 导出限制 10000 条防溢出,自动记录审计日志 - JSON 格式向后兼容 (format=json) - 前端 exportLogs 传递查询参数 同时包含累积的前期工作: - 目录重构 internal/ -> controller/model/router (v0.55-v0.57) - 后端分层架构 dto/repository/service/utils - 审计模块全功能 (终端审计/操作审计/登录日志) - asciicast v2 录制格式 - SFTP 文件浏览器 - StatStrip 紧凑统计条 - 在线会话自动刷新 - LiveMonitor WebSocket 诊断修复 验证: go build ✅ | npm run build ✅ | Docker 部署 ✅ | 10 回归端点 ✅ | CSV 导出 ✅ | 静默 CRUD ✅
This commit is contained in:
1 parent
e57718998a
commit
77c234b060
314 files changed
+10050
-4065
No files matched your search
@@ -0,0 +1,73 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
//go:embed all:static
|
||||
var frontendFS embed.FS
|
||||
|
||||
// setupFrontend 配置前端静态文件服务(go:embed 模式) // Logan.Li
|
||||
// 前端构建产物放在 backend/static/ 目录,编译时嵌入二进制
|
||||
func setupFrontend(r *gin.Engine) {
|
||||
// 获取 static 子目录的 fs.FS
|
||||
staticFS, err := fs.Sub(frontendFS, "static")
|
||||
if err != nil {
|
||||
// static 目录不存在(开发模式或未构建前端),跳过
|
||||
return
|
||||
}
|
||||
httpFS := http.FS(staticFS)
|
||||
|
||||
// 静态资源文件(js/css/图片等)直接返回
|
||||
r.Use(func(c *gin.Context) {
|
||||
// API 和 WebSocket 路径不走静态文件
|
||||
path := c.Request.URL.Path
|
||||
if strings.HasPrefix(path, "/api/") ||
|
||||
strings.HasPrefix(path, "/ws/") ||
|
||||
strings.HasPrefix(path, "/agent/") ||
|
||||
strings.HasPrefix(path, "/health") ||
|
||||
strings.HasPrefix(path, "/version") {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// NoRoute: SPA fallback — 非 API 请求尝试静态文件,找不到则返回 index.html
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
path := c.Request.URL.Path
|
||||
|
||||
// API/WS 路径返回 JSON 404
|
||||
if strings.HasPrefix(path, "/api/") || strings.HasPrefix(path, "/ws/") || strings.HasPrefix(path, "/agent/") {
|
||||
c.JSON(http.StatusNotFound, gin.H{"code": 404, "message": "接口不存在"})
|
||||
return
|
||||
}
|
||||
|
||||
// 尝试打开静态文件
|
||||
cleanPath := strings.TrimPrefix(path, "/")
|
||||
if cleanPath == "" {
|
||||
cleanPath = "index.html"
|
||||
}
|
||||
|
||||
f, err := staticFS.Open(cleanPath)
|
||||
if err == nil {
|
||||
f.Close()
|
||||
c.Header("Cache-Control", "public, max-age=31536000")
|
||||
c.FileFromFS(path, httpFS)
|
||||
return
|
||||
}
|
||||
|
||||
// SPA fallback → 直接返回 index.html 字节(避免 http.FileServer 的 301 redirect)
|
||||
indexBytes, err := fs.ReadFile(staticFS, "index.html")
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, "前端文件缺失")
|
||||
return
|
||||
}
|
||||
c.Data(http.StatusOK, "text/html; charset=utf-8", indexBytes)
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user