"use client"; import * as React from "react"; import { ArrowDownIcon, ArrowUpIcon, PlusIcon } from "lucide-react"; import { toast } from "sonner"; import { TrafficEvidenceViewer } from "@/components/traffic-evidence-viewer"; import { TrafficPickerDialog } from "@/components/traffic-picker-dialog"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from "@/components/ui/empty"; import { Field, FieldGroup, FieldLabel } from "@/components/ui/field"; import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Skeleton } from "@/components/ui/skeleton"; import { Textarea } from "@/components/ui/textarea"; import { api } from "@/lib/api"; import type { FindingTraffic, FindingTrafficBinding, TrafficEvidenceRole } from "@/lib/types"; const ROLES: Record = { baseline: "正常对照", proof: "漏洞证明", verification: "补充验证", supporting: "辅助证据", }; export function FindingTrafficPanel({ findingId, contextTask, readOnly, onChanged, }: { findingId: string; contextTask?: string; readOnly?: boolean; onChanged: () => void; }) { const [data, setData] = React.useState(null); const [error, setError] = React.useState(""); const [adding, setAdding] = React.useState(false); const [preview, setPreview] = React.useState(null); const [editing, setEditing] = React.useState(null); const [role, setRole] = React.useState("supporting"); const [note, setNote] = React.useState(""); const [busy, setBusy] = React.useState(false); const [reload, setReload] = React.useState(0); // biome-ignore lint/correctness/useExhaustiveDependencies: retry token intentionally refreshes this request. React.useEffect(() => { let active = true; setData(null); setError(""); api .findingTraffic(findingId, contextTask) .then((value) => { if (active) setData(value); }) .catch((e: Error) => { if (active) setError(e.message); }); return () => { active = false; }; }, [findingId, contextTask, reload]); async function mutate(action: () => Promise) { setBusy(true); try { setData(await action()); setEditing(null); onChanged(); toast.success("流量证据已更新"); } catch (e) { toast.error((e as Error).message); setReload((n) => n + 1); } finally { setBusy(false); } } function move(index: number, delta: number) { if (!data) return; const ids = data.bindings.map((b) => b.id); [ids[index], ids[index + delta]] = [ids[index + delta], ids[index]]; void mutate(() => api.orderFindingTraffic(findingId, ids, data.version, contextTask)); } return ( <>
关联流量 {data ? `(${data.bindings.length})` : ""} {!readOnly ? ( ) : ( 继承证据 · 只读 )}
按复现顺序组织请求与响应。清理原始流量后,已绑定证据仍然保留。
{error ? ( {error} ) : null} {!data ? ( ) : data.bindings.length === 0 ? ( 暂无关联流量 可绑定正常对照、漏洞证明和补充验证请求。 ) : ( data.bindings.map((b, index) => (
{index + 1}. {ROLES[b.role]} {b.snapshot.method} · {b.snapshot.status} 证据 #{b.id}
{b.note ?

{b.note}

: null}
{new Date(b.snapshot.captured_at * 1000).toLocaleString("zh-CN")}
{!readOnly ? ( <> ) : null}
)) )}
{adding && data ? ( setAdding(false)} onBound={() => { setReload((n) => n + 1); onChanged(); }} /> ) : null} setPreview(null)} /> { if (!open && !busy) setEditing(null); }} > 编辑流量证据 说明这组请求/响应如何支持漏洞结论。 用途 证据说明