import { Handle, Position, type NodeProps } from '@xyflow/react'; import { Ban, Fingerprint, Flag, Globe2, Play, ShieldCheck, } from 'lucide-react'; import { Badge } from '@/components/ui/badge'; import { cn } from '@/lib/utils'; import type { WAFRuleNode } from '@/lib/services/openflare'; export interface RuleFlowNodeData extends Record { rule: WAFRuleNode; issues: number; } const meta = { start: { label: '开始', icon: Play }, ip_match: { label: 'IP 匹配', icon: Fingerprint }, geo_match: { label: '地域匹配', icon: Globe2 }, pow: { label: 'PoW 挑战', icon: ShieldCheck }, allow: { label: '通过', icon: Flag }, block: { label: '阻止', icon: Ban }, } as const; const outputHandles: Partial> = { start: ['next'], ip_match: ['true', 'false'], geo_match: ['true', 'false'], pow: ['next'], }; export function RuleNode({ data, selected }: NodeProps) { const value = data as RuleFlowNodeData; const { rule, issues } = value; const { label, icon: Icon } = meta[rule.type]; return (
0 && 'border-destructive', )} > {rule.type !== 'start' && ( )}
{label} {rule.id}
{issues > 0 && {issues}}
{(outputHandles[rule.type] ?? []).map((handle, index, all) => ( {handle} ))}
); }