/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import { Download as ActionDownload } from '@/components/common/icons/ActionIcons';
import React, {
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import { useTranslation } from 'react-i18next';
import {
Card,
Spin,
Select,
Button,
Tag,
Table,
Empty,
Toast,
} from '@/components/ui';
import { IconRefresh } from '@/components/ui/icons';
import { initVChartTheme } from '@/components/ui/chartTheme';
import { VChart } from '@visactor/react-vchart';
import {
Upload,
CheckCircle2,
XCircle,
AlertTriangle,
Users,
} from 'lucide-react';
import { API, showError } from '../../helpers';
import { exportToCsv, formatTimestampForCsv } from '../../helpers/exportCsv';
// 时间范围选项(小时):与 admin 后台后端 uploadAuditMaxRangeHours=720 保持一致
const RANGE_OPTIONS_BUILDER = (t) => [
{ label: t('最近 1 小时'), value: 1 },
{ label: t('最近 24 小时'), value: 24 },
{ label: t('最近 7 天'), value: 24 * 7 },
{ label: t('最近 30 天'), value: 24 * 30 },
];
// event 大类筛选下拉
const EVENT_FILTER_BUILDER = (t) => [
{ label: t('全部事件'), value: '' },
{ label: t('成功'), value: 'success' },
{ label: t('失败(全部)'), value: 'failed' },
{ label: t('警告'), value: 'warning' },
// 高频精细原因,便于快速定位
{ label: t('体积超限'), value: 'rejected_size' },
{ label: t('格式不支持'), value: 'rejected_unsupported_format' },
{ label: t('策略禁止'), value: 'rejected_by_policy' },
{ label: t('COS 上传失败'), value: 'rejected_cos_upload_failed' },
{ label: t('文件内容伪装'), value: 'rejected_corrupt_image' },
{ label: t('对话期 URL 失效'), value: 'inline_failed' },
];
// event → 中文短描述(i18n key 同名)
const EVENT_LABEL = (t, evt) => {
if (!evt) return '';
const map = {
success: t('成功'),
rejected_disabled: t('功能未启用'),
rejected_cos_unavailable: t('存储未就绪'),
rejected_missing_file: t('未提供文件'),
rejected_size: t('体积超限'),
rejected_unsupported_format: t('格式不支持'),
rejected_by_policy: t('策略禁止'),
rejected_read_failed: t('读取失败'),
rejected_corrupt_image: t('文件内容伪装'),
rejected_cos_upload_failed: t('COS 上传失败'),
warn_presign_failed: t('预签名失败'),
rejected_foreign_url: t('非法 URL'),
inline_failed: t('对话期 URL 失效'),
};
return map[evt] || evt;
};
const eventColor = (evt) => {
if (evt === 'success') return 'green';
if (evt.startsWith('warn_')) return 'orange';
if (evt === 'inline_failed') return 'red';
if (evt.startsWith('rejected_')) return 'red';
return 'grey';
};
const StatCard = ({ icon, label, value, accent }) => (