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:
attacker committed 2026-06-25 20:16:30 +08:00
1 parent e57718998a
commit 77c234b060
314 files changed
+10050 -4065

No files matched your search

+26 -21
View File
@@ -15,12 +15,8 @@ export interface ListResponse<T = unknown> {
total: number;
}
// 可序列化为 JSON 的请求体类型
// 注: 使用 unknown 接受任意 body(前端 API 层会 JSON.stringify)
type Json = unknown;
// 通用请求函数
// 注: 默认返回类型为 any 以兼容动态后端响应;调用方应通过泛型参数指定具体类型
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async function request<T = any>(
method: string,
@@ -28,7 +24,6 @@ async function request<T = any>(
body?: Json,
params?: Record<string, string | number | boolean | undefined>
): Promise<T> {
// 构建 URL(含 query params)
let fullUrl = `${BASE_URL}${url}`;
if (params) {
const searchParams = new URLSearchParams();
@@ -38,17 +33,16 @@ async function request<T = any>(
}
});
const qs = searchParams.toString();
if (qs) fullUrl += `?${qs}`;
if (qs) fullUrl += '?' + qs;
}
// 获取 token
const token = useUserStore.getState().token || localStorage.getItem('token');
const headers: Record<string, string> = {
'Content-Type': 'application/json',
};
if (token) {
headers['Authorization'] = `Bearer ${token}`;
headers['Authorization'] = 'Bearer ' + token;
}
const response = await fetch(fullUrl, {
@@ -69,12 +63,9 @@ async function request<T = any>(
throw new Error(json.message || '请求失败');
}
// Return json.data for standard responses, or full json for non-standard ones
return (json.data !== undefined ? json.data : json) as T;
}
// 导出便捷方法
// 注: 默认泛型为 any 以兼容动态后端响应
export const http = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
get: <T = any>(url: string, params?: Record<string, string | number | boolean | undefined>) =>
@@ -92,40 +83,54 @@ export const http = {
getRaw: async (url: string): Promise<string> => {
const tk = useUserStore.getState().token;
const baseUrl = import.meta.env.VITE_API_BASE_URL || '';
const resp = await fetch(`${baseUrl}/api/v1${url}`, { headers: { Authorization: `Bearer ${tk}` } });
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
const resp = await fetch(baseUrl + '/api/v1' + url, { headers: { Authorization: 'Bearer ' + tk } });
if (!resp.ok) throw new Error('HTTP ' + resp.status);
return resp.text();
},
putRaw: async (url: string, body: string, contentType: string): Promise<unknown> => {
const tk = useUserStore.getState().token;
const baseUrl = import.meta.env.VITE_API_BASE_URL || '';
const resp = await fetch(`${baseUrl}/api/v1${url}`, {
const resp = await fetch(baseUrl + '/api/v1' + url, {
method: 'PUT',
headers: { Authorization: `Bearer ${tk}`, 'Content-Type': contentType },
headers: { Authorization: 'Bearer ' + tk, 'Content-Type': contentType },
body,
});
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
if (!resp.ok) throw new Error('HTTP ' + resp.status);
return resp.json();
},
// 二进制下载(blob)— 用于 tar.gz / 文件下载
download: async (url: string, filename?: string): Promise<void> => {
const tk = useUserStore.getState().token;
const baseUrl = import.meta.env.VITE_API_BASE_URL || '';
const resp = await fetch(`${baseUrl}/api/v1${url}`, {
headers: { Authorization: `Bearer ${tk}` },
const resp = await fetch(baseUrl + '/api/v1' + url, {
headers: { Authorization: 'Bearer ' + tk },
});
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
if (!resp.ok) throw new Error('HTTP ' + resp.status);
const blob = await resp.blob();
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = filename || resp.headers.get('Content-Disposition')?.match(/filename="?(.+?)"?$/)?.[1] || 'download';
const disp = resp.headers.get('Content-Disposition') || '';
const m = disp.match(/filename="?(.+?)"?$/);
a.download = filename || (m ? m[1] : 'download');
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(a.href);
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
upload: async <T = any>(url: string, formData: FormData): Promise<T> => {
const tk = useUserStore.getState().token;
const baseUrl = import.meta.env.VITE_API_BASE_URL || '';
const resp = await fetch(baseUrl + '/api/v1' + url, {
method: 'POST',
headers: { Authorization: 'Bearer ' + tk },
body: formData,
});
if (!resp.ok) throw new Error('HTTP ' + resp.status);
return resp.json();
},
};
export default http;