Skip to content

A modern and elegant dashboard for network traffic visualization and analysis.

feat: Introduce Clash API proxying to the collector, enable active proxy chain resolution, and display zero-traffic rules in the UI.

luoleid2b9655e795e
diff --git a/apps/collector/src/api.ts b/apps/collector/src/api.ts
index a87e0a9..825ccc2 100644
--- a/apps/collector/src/api.ts
+++ b/apps/collector/src/api.ts
@@ -603,6 +603,70 @@ export class APIServer {
return { message: 'Backend data cleared successfully' };
});
+ // Clash API proxy endpoints
+ // Get providers/proxies from Clash backend
+ app.get('/api/clash/providers/proxies', async (request, reply) => {
+ const backendId = getBackendId(request);
+ if (backendId === null) {
+ return reply.status(404).send({ error: 'No backend specified or active' });
+ }
+ const backend = this.db.getBackend(backendId);
+ if (!backend) {
+ return reply.status(404).send({ error: 'Backend not found' });
+ }
+
+ // Derive Clash REST base URL from the stored WebSocket URL
+ const clashBaseUrl = backend.url
+ .replace('ws://', 'http://').replace('wss://', 'https://')
+ .replace(/\/connections\/?$/, '');
+
+ const headers: Record<string, string> = { 'Content-Type': 'application/json' };
+ if (backend.token) {
+ headers['Authorization'] = `Bearer ${backend.token}`;
+ }
+
+ try {
+ const res = await fetch(`${clashBaseUrl}/providers/proxies`, { headers });
+ if (!res.ok) {
+ return reply.status(res.status).send({ error: `Clash API error: ${res.status}` });
+ }
+ return res.json();
+ } catch (err: any) {
+ return reply.status(502).send({ error: err.message || 'Failed to reach Clash API' });
+ }
+ });
+
+ // Get rules from Clash backend
+ app.get('/api/clash/rules', async (request, reply) => {
+ const backendId = getBackendId(request);
+ if (backendId === null) {
+ return reply.status(404).send({ error: 'No backend specified or active' });
+ }
+ const backend = this.db.getBackend(backendId);
+ if (!backend) {
+ return reply.status(404).send({ error: 'Backend not found' });
+ }
+
+ const clashBaseUrl = backend.url
+ .replace('ws://', 'http://').replace('wss://', 'https://')
+ .replace(/\/connections\/?$/, '');
+
+ const headers: Record<string, string> = { 'Content-Type': 'application/json' };
+ if (backend.token) {
+ headers['Authorization'] = `Bearer ${backend.token}`;
+ }
+
+ try {
+ const res = await fetch(`${clashBaseUrl}/rules`, { headers });
+ if (!res.ok) {
+ return reply.status(res.status).send({ error: `Clash API error: ${res.status}` });
+ }
+ return res.json();
+ } catch (err: any) {
+ return reply.status(502).send({ error: err.message || 'Failed to reach Clash API' });
+ }
+ });
+
// Database management APIs
// Get database stats
app.get('/api/db/stats', async () => {
diff --git a/apps/web/components/interactive-rule-stats.tsx b/apps/web/components/interactive-rule-stats.tsx
index 5fa185e..b8f4bf3 100644
--- a/apps/web/components/interactive-rule-stats.tsx
+++ b/apps/web/components/interactive-rule-stats.tsx
@@ -18,7 +18,7 @@ import {
} from "@/components/ui/dropdown-menu";
import { formatBytes, formatNumber } from "@/lib/utils";
import { cn } from "@/lib/utils";
-import { api } from "@/lib/api";
+import { api, type ClashRulesResponse } from "@/lib/api";
import { Favicon } from "@/components/favicon";
import { UnifiedRuleChainFlow } from "@/components/rule-chain-flow";
import type { RuleStats, DomainStats, IPStats } from "@clashmaster/shared";
@@ -145,6 +145,7 @@ export function InteractiveRuleStats({ data, activeBackendId }: InteractiveRuleS
const [ipPageSize, setIpPageSize] = useState<PageSize>(10);
const [ipSearch, setIpSearch] = useState("");
const [showDomainBarLabels, setShowDomainBarLabels] = useState(true);
+ const [clashRules, setClashRules] = useState<ClashRulesResponse | null>(null);
// Sort states
const [domainSortKey, setDomainSortKey] = useState<DomainSortKey>("totalDownload");
@@ -164,9 +165,26 @@ export function InteractiveRuleStats({ data, activeBackendId }: InteractiveRuleS
return () => media.removeEventListener("change", update);
}, []);
+ // Fetch Clash rules to find zero-traffic rules
+ useEffect(() => {
+ let cancelled = false;
+ async function fetchClashRules() {
+ try {
+ const result = await api.getClashRules(activeBackendId);
+ if (!cancelled) setClashRules(result);
+ } catch {
+ // Silent - Clash API may not be available
+ }
+ }
+ fetchClashRules();
+ const interval = setInterval(fetchClashRules, 30000);
+ return () => { cancelled = true; clearInterval(interval); };
+ }, [activeBackendId]);
+
const chartData = useMemo(() => {
if (!data) return [];
- return data.map((rule, index) => ({
+ const existingRuleNames = new Set(data.map(r => r.rule));
+ const trafficItems = data.map((rule, index) => ({
name: rule.rule,
rawName: rule.rule,
value: rule.totalDownload + rule.totalUpload,
@@ -176,8 +194,37 @@ export function InteractiveRuleStats({ data, activeBackendId }: InteractiveRuleS
finalProxy: rule.finalProxy,
color: COLORS[index % COLORS.length],
rank: index,
+ hasTraffic: true,
}));
- }, [data]);
+
+ // Append zero-traffic rules from Clash API, using the target proxy group name
+ // (rule.proxy) which matches how traffic data stores rule names.
+ // Multiple low-level rules (RuleSet, ProcessName, etc.) can target the same
+ // proxy group, so we deduplicate by proxy group name.
+ if (clashRules?.rules) {
+ const zeroTrafficItems: typeof trafficItems = [];
+ for (const rule of clashRules.rules) {
+ const proxyGroup = rule.proxy;
+ if (existingRuleNames.has(proxyGroup)) continue;
+ existingRuleNames.add(proxyGroup);
+ zeroTrafficItems.push({
+ name: proxyGroup,
+ rawName: proxyGroup,
+ value: 0,
+ download: 0,
+ upload: 0,
+ connections: 0,
+ finalProxy: proxyGroup,
+ color: "#9CA3AF",
+ rank: trafficItems.length + zeroTrafficItems.length,
+ hasTraffic: false,
+ });
+ }
+ return [...trafficItems, ...zeroTrafficItems];
+ }
+
+ return trafficItems;
+ }, [data, clashRules]);
const totalTraffic = useMemo(() => {
return chartData.reduce((sum, item) => sum + item.value, 0);
@@ -494,11 +541,14 @@ export function InteractiveRuleStats({ data, activeBackendId }: InteractiveRuleS
<div className="space-y-2">
{chartData.map((item) => {
const percentage = totalTraffic > 0 ? (item.value / totalTraffic) * 100 : 0;
- const barPercent = (item.value / maxTotal) * 100;
+ const barPercent = maxTotal > 0 ? (item.value / maxTotal) * 100 : 0;
const isSelected = selectedRule === item.rawName;
-
+ const noTraffic = !item.hasTraffic;
+
// Badge color based on rank
- const badgeColor = item.rank === 0
+ const badgeColor = noTraffic
+ ? "bg-muted text-muted-foreground"
+ : item.rank === 0
? "bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400"
: item.rank === 1
? "bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300"
@@ -509,10 +559,12 @@ export function InteractiveRuleStats({ data, activeBackendId }: InteractiveRuleS
return (
<button
key={item.rawName}
- onClick={() => handleRuleClick(item.rawName)}
+ onClick={() => !noTraffic && handleRuleClick(item.rawName)}
className={cn(
"w-full p-2.5 rounded-xl border text-left transition-all duration-200",
- isSelected
+ noTraffic
+ ? "border-border/30 bg-card/30 opacity-50 cursor-default"
+ : isSelected
? "border-primary bg-primary/5 ring-1 ring-primary/20"
: "border-border/50 bg-card/50 hover:bg-card hover:border-primary/30"
)}>
@@ -522,29 +574,32 @@ export function InteractiveRuleStats({ data, activeBackendId }: InteractiveRuleS
"w-5 h-5 rounded-md text-[10px] font-bold flex items-center justify-center shrink-0",
badgeColor
)}>
- {item.rank + 1}
+ {noTraffic ? "–" : item.rank + 1}
</span>
-
+
<span className="flex-1 text-sm font-medium truncate" title={item.name}>
{item.name}
</span>
-
+
<span className="text-sm font-bold tabular-nums shrink-0">
- {formatBytes(item.value)}
+ {noTraffic ? (
+ <span className="text-xs font-normal text-muted-foreground">{t("noTrafficRecord")}</span>
+ ) : formatBytes(item.value)}
</span>
</div>
- {/* Row 2: Progress bar + Stats */}
+ {/* Row 2: Progress bar + Stats (hidden for zero-traffic) */}
+ {!noTraffic && (
<div className="pl-7 space-y-1">
{/* Progress bar - dual color */}
<div className="h-1.5 rounded-full bg-muted overflow-hidden flex">
- <div
- className="h-full bg-blue-500 dark:bg-blue-400"
- style={{ width: `${(item.download / item.value) * barPercent}%` }}
+ <div
+ className="h-full bg-blue-500 dark:bg-blue-400"
+ style={{ width: `${item.value > 0 ? (item.download / item.value) * barPercent : 0}%` }}
/>
- <div
- className="h-full bg-purple-500 dark:bg-purple-400"
- style={{ width: `${(item.upload / item.value) * barPercent}%` }}
+ <div
+ className="h-full bg-purple-500 dark:bg-purple-400"
+ style={{ width: `${item.value > 0 ? (item.upload / item.value) * barPercent : 0}%` }}
/>
</div>
{/* Stats */}
@@ -560,6 +615,7 @@ export function InteractiveRuleStats({ data, activeBackendId }: InteractiveRuleS
<span className="tabular-nums">{percentage.toFixed(1)}%</span>
</div>
</div>
+ )}
</button>
);
})}
diff --git a/apps/web/components/navigation.tsx b/apps/web/components/navigation.tsx
index c2fe57f..43324fd 100644
--- a/apps/web/components/navigation.tsx
+++ b/apps/web/components/navigation.tsx
@@ -14,6 +14,7 @@ import {
ExternalLink,
ArrowUpCircle,
RefreshCw,
+ X,
} from "lucide-react";
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
@@ -202,11 +203,17 @@ export function Navigation({
if (e.target === e.currentTarget) setAboutOpen(false);
}}>
<Card className="w-full max-w-[420px]">
- <CardHeader>
+ <CardHeader className="flex flex-row items-center justify-between">
<CardTitle className="flex items-center gap-2">
<Info className="w-5 h-5 text-primary" />
{aboutT("title")}
</CardTitle>
+ <button
+ onClick={() => setAboutOpen(false)}
+ className="p-1.5 rounded-lg text-muted-foreground hover:text-foreground hover:bg-secondary transition-colors -mr-1.5"
+ aria-label="Close">
+ <X className="w-5 h-5" />
+ </button>
</CardHeader>
<CardContent>
{/* App Info */}
diff --git a/apps/web/components/overview/top-proxies-simple.tsx b/apps/web/components/overview/top-proxies-simple.tsx
index 08028c5..dd4feb0 100644
--- a/apps/web/components/overview/top-proxies-simple.tsx
+++ b/apps/web/components/overview/top-proxies-simple.tsx
@@ -19,164 +19,187 @@ function simplifyProxyName(name: string): string {
return name.trim();
}
-export const TopProxiesSimple = React.memo(function TopProxiesSimple({
- proxies,
- sortBy,
- onSortChange,
- onViewAll,
-}: TopProxiesSimpleProps) {
- const t = useTranslations("topProxies");
-
- const sortedProxies = useMemo(() => {
- if (!proxies?.length) return [];
-
- const sorted = [...proxies].sort((a, b) => {
- if (sortBy === "traffic") {
- const totalA = a.totalDownload + a.totalUpload;
- const totalB = b.totalDownload + b.totalUpload;
- return totalB - totalA;
- } else {
- return b.totalConnections - a.totalConnections;
- }
- });
-
- return sorted.slice(0, 6);
- }, [proxies, sortBy]);
-
- const maxTotal = useMemo(() => {
- if (!sortedProxies.length) return 1;
- return Math.max(...sortedProxies.map(p => p.totalDownload + p.totalUpload));
- }, [sortedProxies]);
-
- const totalTraffic = useMemo(() => {
- if (!proxies?.length) return 1;
- return proxies.reduce((sum, p) => sum + p.totalDownload + p.totalUpload, 0);
- }, [proxies]);
-
- return (
- <div className="space-y-3 h-full flex flex-col">
- {/* Header */}
- <div className="flex items-center justify-between">
- <h3 className="text-sm font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2">
- <Server className="w-4 h-4" />
- {t("title")}
- </h3>
-
- {/* Sort toggle */}
- <div className="flex items-center gap-0.5 bg-muted/50 rounded-lg p-0.5">
- <Button
- variant="ghost"
- size="icon"
- className={cn(
- "h-7 w-7 rounded-md transition-all",
- sortBy === "traffic"
- ? "bg-background shadow-sm text-primary"
- : "text-muted-foreground hover:text-foreground"
- )}
- onClick={() => onSortChange("traffic")}
- title={t("sortByTraffic")}
- >
- <BarChart3 className="w-4 h-4" />
- </Button>
- <Button
- variant="ghost"
- size="icon"
- className={cn(
- "h-7 w-7 rounded-md transition-all",
- sortBy === "connections"
- ? "bg-background shadow-sm text-primary"
- : "text-muted-foreground hover:text-foreground"
- )}
- onClick={() => onSortChange("connections")}
- title={t("sortByConnections")}
- >
- <Link2 className="w-4 h-4" />
- </Button>
+export const TopProxiesSimple = React.memo(
+ function TopProxiesSimple({
+ proxies,
+ sortBy,
+ onSortChange,
+ onViewAll,
+ }: TopProxiesSimpleProps) {
+ const t = useTranslations("topProxies");
+
+ const sortedProxies = useMemo(() => {
+ if (!proxies?.length) return [];
+
+ const sorted = [...proxies].sort((a, b) => {
+ if (sortBy === "traffic") {
+ const totalA = a.totalDownload + a.totalUpload;
+ const totalB = b.totalDownload + b.totalUpload;
+ return totalB - totalA;
+ } else {
+ return b.totalConnections - a.totalConnections;
+ }
+ });
+
+ return sorted.slice(0, 6);
+ }, [proxies, sortBy]);
+
+ const maxTotal = useMemo(() => {
+ if (!sortedProxies.length) return 1;
+ return Math.max(
+ ...sortedProxies.map((p) => p.totalDownload + p.totalUpload),
+ );
+ }, [sortedProxies]);
+
+ const totalTraffic = useMemo(() => {
+ if (!proxies?.length) return 1;
+ return proxies.reduce(
+ (sum, p) => sum + p.totalDownload + p.totalUpload,
+ 0,
+ );
+ }, [proxies]);
+
+ return (
+ <div className="space-y-3 h-full flex flex-col">
+ {/* Header */}
+ <div className="flex items-center justify-between">
+ <h3 className="text-sm font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2">
+ <Server className="w-4 h-4" />
+ {t("title")}
+ </h3>
+
+ {/* Sort toggle */}
+ <div className="flex items-center gap-0.5 bg-muted/50 rounded-lg p-0.5">
+ <Button
+ variant="ghost"
+ size="icon"
+ className={cn(
+ "h-7 w-7 rounded-md transition-all",
+ sortBy === "traffic"
+ ? "bg-background shadow-sm text-primary"
+ : "text-muted-foreground hover:text-foreground",
+ )}
+ onClick={() => onSortChange("traffic")}
+ title={t("sortByTraffic")}>
+ <BarChart3 className="w-4 h-4" />
+ </Button>
+ <Button
+ variant="ghost"
+ size="icon"
+ className={cn(
+ "h-7 w-7 rounded-md transition-all",
+ sortBy === "connections"
+ ? "bg-background shadow-sm text-primary"
+ : "text-muted-foreground hover:text-foreground",
+ )}
+ onClick={() => onSortChange("connections")}
+ title={t("sortByConnections")}>
+ <Link2 className="w-4 h-4" />
+ </Button>
+ </div>
</div>
- </div>
- {/* List */}
- <div className="space-y-2 flex-1">
- {sortedProxies.map((proxyItem, index) => {
- const total = proxyItem.totalDownload + proxyItem.totalUpload;
- const displayName = simplifyProxyName(proxyItem.chain);
- const badgeColor = index === 0
- ? "bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400"
- : index === 1
- ? "bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300"
- : index === 2
- ? "bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-400"
- : "bg-muted text-muted-foreground";
-
- const barPercent = (total / maxTotal) * 100;
- const sharePercent = (total / totalTraffic) * 100;
-
- return (
- <div
- key={proxyItem.chain}
- className="p-2.5 rounded-xl border border-border/50 bg-card/50 hover:bg-card transition-colors"
- >
- {/* Row 1: Rank + Name + Total */}
- <div className="flex items-center gap-2 mb-1.5">
- <span className={cn(
- "w-5 h-5 rounded-md text-[10px] font-bold flex items-center justify-center shrink-0",
- badgeColor
- )}>
- {index + 1}
- </span>
-
- <span className="flex-1 text-sm font-medium truncate" title={proxyItem.chain}>
- {displayName || proxyItem.chain}
- </span>
-
- <span className="text-sm font-bold tabular-nums shrink-0">
- {formatBytes(total)}
- </span>
- </div>
+ {/* List */}
+ <div className="space-y-2 flex-1">
+ {sortedProxies.map((proxyItem, index) => {
+ const total = proxyItem.totalDownload + proxyItem.totalUpload;
+ const displayName = simplifyProxyName(proxyItem.chain);
+ const badgeColor =
+ index === 0
+ ? "bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400"
+ : index === 1
+ ? "bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300"
+ : index === 2
+ ? "bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-400"
+ : "bg-muted text-muted-foreground";
+
+ const barPercent = (total / maxTotal) * 100;
+ const sharePercent = (total / totalTraffic) * 100;
+
+ return (
+ <div
+ key={proxyItem.chain}
+ className="p-2.5 rounded-xl border border-border/50 bg-card/50 hover:bg-card transition-colors">
+ {/* Row 1: Rank + Name + Total */}
+ <div className="flex items-center gap-2 mb-1.5">
+ <span
+ className={cn(
+ "w-5 h-5 rounded-md text-[10px] font-bold flex items-center justify-center shrink-0",
+ badgeColor,
+ )}>
+ {index + 1}
+ </span>
- {/* Row 2: Progress bar + Stats */}
- <div className="pl-7 space-y-1.5">
- {/* Progress bar */}
- <div className="h-1.5 rounded-full bg-muted overflow-hidden flex">
- <div
- className="h-full bg-blue-500 dark:bg-blue-400"
- style={{ width: `${(proxyItem.totalDownload / total) * barPercent}%` }}
- />
- <div
- className="h-full bg-purple-500 dark:bg-purple-400"
- style={{ width: `${(proxyItem.totalUpload / total) * barPercent}%` }}
- />
+ <span
+ className="flex-1 text-sm font-medium truncate"
+ title={proxyItem.chain}>
+ {displayName || proxyItem.chain}
+ </span>
+
+ <span className="text-sm font-bold tabular-nums shrink-0">
+ {formatBytes(total)}
+ </span>
</div>
- {/* Stats */}
- <div className="flex items-center justify-between text-xs text-muted-foreground">
- <div className="flex items-center gap-2">
- <span className="text-blue-500 dark:text-blue-400">↓ {formatBytes(proxyItem.totalDownload)}</span>
- <span className="text-purple-500 dark:text-purple-400">↑ {formatBytes(proxyItem.totalUpload)}</span>
- <span className="flex items-center gap-1 tabular-nums">
- <Link2 className="w-3 h-3" />
- {formatNumber(proxyItem.totalConnections)}
+
+ {/* Row 2: Progress bar + Stats */}
+ <div className="pl-7 space-y-1.5">
+ {/* Progress bar */}
+ <div className="h-1.5 rounded-full bg-muted overflow-hidden flex">
+ <div
+ className="h-full bg-blue-500 dark:bg-blue-400"
+ style={{
+ width: `${(proxyItem.totalDownload / total) * barPercent}%`,
+ }}
+ />
+ <div
+ className="h-full bg-purple-500 dark:bg-purple-400"
+ style={{
+ width: `${(proxyItem.totalUpload / total) * barPercent}%`,
+ }}
+ />
+ </div>
+ {/* Stats */}
+ <div className="flex items-center justify-between text-xs text-muted-foreground">
+ <div className="flex items-center gap-2">
+ <span className="text-blue-500 dark:text-blue-400">
+ ↓ {formatBytes(proxyItem.totalDownload)}
+ </span>
+ <span className="text-purple-500 dark:text-purple-400">
+ ↑ {formatBytes(proxyItem.totalUpload)}
+ </span>
+ <span className="flex items-center gap-1 tabular-nums">
+ <Link2 className="w-3 h-3" />
+ {formatNumber(proxyItem.totalConnections)}
+ </span>
+ </div>
+ <span className="tabular-nums">
+ {sharePercent.toFixed(1)}%
</span>
</div>
- <span className="tabular-nums">{sharePercent.toFixed(1)}%</span>
</div>
</div>
- </div>
- );
- })}
- </div>
+ );
+ })}
+ </div>
- {/* Footer */}
- <div className="pt-2 border-t border-border/30">
- <Button variant="ghost" size="sm" className="w-full h-9 text-xs" onClick={onViewAll}>
- {t("viewAll")}
- <ArrowRight className="w-3 h-3 ml-1" />
- </Button>
+ {/* Footer */}
+ <div className="pt-2 border-t border-border/30">
+ <Button
+ variant="ghost"
+ size="sm"
+ className="w-full h-9 text-xs"
+ onClick={onViewAll}>
+ {t("viewAll")}
+ <ArrowRight className="w-3 h-3 ml-1" />
+ </Button>
+ </div>
</div>
- </div>
- );
-}, (prev, next) => {
- return (
- JSON.stringify(prev.proxies) === JSON.stringify(next.proxies) &&
- prev.sortBy === next.sortBy
- );
-});
+ );
+ },
+ (prev, next) => {
+ return (
+ JSON.stringify(prev.proxies) === JSON.stringify(next.proxies) &&
+ prev.sortBy === next.sortBy
+ );
+ },
+);
diff --git a/apps/web/components/rule-chain-flow.tsx b/apps/web/components/rule-chain-flow.tsx
index 750dea1..5f4a760 100644
--- a/apps/web/components/rule-chain-flow.tsx
+++ b/apps/web/components/rule-chain-flow.tsx
@@ -17,12 +17,13 @@ import {
useEdgesState,
} from "@xyflow/react";
import "@xyflow/react/dist/style.css";
-import { Workflow, Loader2, Server, Layers, Eye } from "lucide-react";
+import { Workflow, Loader2, Server, Layers, Eye, Activity } from "lucide-react";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { cn, formatBytes, formatNumber } from "@/lib/utils";
import { useTheme } from "next-themes";
import { api } from "@/lib/api";
+import { resolveActiveChains, type ActiveChainInfo } from "@/lib/active-chain";
import { useTranslations } from "next-intl";
// ---------- Types ----------
@@ -65,28 +66,40 @@ function MergedAnimatedFlowEdge({
data,
}: EdgeProps) {
const edgeData = data as
- | { isToProxy?: boolean; dimmed?: boolean; showAll?: boolean }
+ | {
+ isToProxy?: boolean;
+ dimmed?: boolean;
+ showAll?: boolean;
+ _zeroTraffic?: boolean;
+ }
| undefined;
const isToProxy = edgeData?.isToProxy;
const dimmed = edgeData?.dimmed;
const showAll = edgeData?.showAll;
+ const zeroTraffic = edgeData?._zeroTraffic;
const [edgePath] = getStraightPath({ sourceX, sourceY, targetX, targetY });
- const dotColor = isToProxy ? "#34d399" : "#a5b4fc";
- const trackColor = isToProxy
- ? "rgba(16, 185, 129, 0.12)"
- : "rgba(129, 140, 248, 0.12)";
- const lineColor = isToProxy
- ? "rgba(16, 185, 129, 0.3)"
- : "rgba(129, 140, 248, 0.3)";
-
- // Particles only when actively highlighted (not dimmed and not showAll overview)
- const showParticles = !dimmed && !showAll;
+ const dotColor = zeroTraffic ? "#9CA3AF" : isToProxy ? "#34d399" : "#a5b4fc";
+ const trackColor = zeroTraffic
+ ? "rgba(156, 163, 175, 0.1)"
+ : isToProxy
+ ? "rgba(16, 185, 129, 0.12)"
+ : "rgba(129, 140, 248, 0.12)";
+ const lineColor = zeroTraffic
+ ? "rgba(156, 163, 175, 0.25)"
+ : isToProxy
+ ? "rgba(16, 185, 129, 0.3)"
+ : "rgba(129, 140, 248, 0.3)";
+
+ // Particles only when actively highlighted (not dimmed, not showAll overview, and not zero-traffic)
+ const showParticles = !dimmed && !showAll && !zeroTraffic;
return (
<g
- style={{ opacity: dimmed ? 0.12 : 1, transition: "opacity 0.4s ease" }}
- >
+ style={{
+ opacity: dimmed ? 0.12 : zeroTraffic ? 0.5 : 1,
+ transition: "opacity 0.4s ease",
+ }}>
<path
d={edgePath}
fill="none"
@@ -138,12 +151,14 @@ function MergedAnimatedFlowEdge({
function MergedChainNodeComponent({
data,
}: {
- data: MergedChainNode & { dimmed?: boolean };
+ data: MergedChainNode & { dimmed?: boolean; _zeroTraffic?: boolean };
}) {
const dimmed = data.dimmed;
- const wrapStyle = {
- opacity: dimmed ? 0.12 : 1,
- transition: "opacity 0.4s ease",
+ const zeroTraffic = (data as any)._zeroTraffic;
+ const wrapStyle: React.CSSProperties = {
+ opacity: dimmed ? 0.12 : zeroTraffic ? 0.5 : 1,
+ filter: zeroTraffic ? "grayscale(100%)" : undefined,
+ transition: "opacity 0.4s ease, filter 0.4s ease",
};
// PROXY node - green theme with PROXY badge
@@ -330,7 +345,7 @@ function FlowRenderer({
dimmed: activeNodeSet ? !activeNodeSet.has(idx) : false,
},
};
- })
+ }),
);
return;
}
@@ -342,16 +357,13 @@ function FlowRenderer({
// Group nodes by layer, sort by traffic within each layer
const layerGroups = new Map<number, number[]>();
data.nodes.forEach((node, idx) => {
- if (!layerGroups.has(node.layer))
- layerGroups.set(node.layer, []);
+ if (!layerGroups.has(node.layer)) layerGroups.set(node.layer, []);
layerGroups.get(node.layer)!.push(idx);
});
for (const [, indices] of layerGroups) {
indices.sort((a, b) => {
- const at =
- data.nodes[a].totalUpload + data.nodes[a].totalDownload;
- const bt =
- data.nodes[b].totalUpload + data.nodes[b].totalDownload;
+ const at = data.nodes[a].totalUpload + data.nodes[a].totalDownload;
+ const bt = data.nodes[b].totalUpload + data.nodes[b].totalDownload;
return bt - at;
});
}
@@ -365,18 +377,15 @@ function FlowRenderer({
const activeByLayer = new Map<number, number[]>();
for (const nodeIdx of activeIndices!.nodeIndices) {
const layer = data.nodes[nodeIdx].layer;
- if (!activeByLayer.has(layer))
- activeByLayer.set(layer, []);
+ if (!activeByLayer.has(layer)) activeByLayer.set(layer, []);
activeByLayer.get(layer)!.push(nodeIdx);
}
// Position active nodes: single → y=0, multiple → fanned vertically around y=0
for (const [layer, indices] of activeByLayer) {
indices.sort((a, b) => {
- const at =
- data.nodes[a].totalUpload + data.nodes[a].totalDownload;
- const bt =
- data.nodes[b].totalUpload + data.nodes[b].totalDownload;
+ const at = data.nodes[a].totalUpload + data.nodes[a].totalDownload;
+ const bt = data.nodes[b].totalUpload + data.nodes[b].totalDownload;
return bt - at;
});
const count = indices.length;
@@ -384,10 +393,7 @@ function FlowRenderer({
indices.forEach((nodeIdx, posInLayer) => {
positions.set(nodeIdx, {
x: layer * COLUMN_WIDTH,
- y:
- posInLayer * NODE_HEIGHT -
- totalHeight / 2 +
- NODE_HEIGHT / 2,
+ y: posInLayer * NODE_HEIGHT - totalHeight / 2 + NODE_HEIGHT / 2,
});
});
}
@@ -402,10 +408,7 @@ function FlowRenderer({
others.forEach((nodeIdx, posInLayer) => {
positions.set(nodeIdx, {
x: layer * COLUMN_WIDTH,
- y:
- maxActiveY +
- OTHER_NODES_OFFSET +
- posInLayer * NODE_HEIGHT,
+ y: maxActiveY + OTHER_NODES_OFFSET + posInLayer * NODE_HEIGHT,
});
});
}
@@ -430,6 +433,7 @@ function FlowRenderer({
data: {
...node,
dimmed: activeNodeSet ? !activeNodeSet.has(idx) : false,
+ _zeroTraffic: !!(node as any)._zeroTraffic,
},
sourcePosition: Position.Right,
targetPosition: Position.Left,
@@ -441,14 +445,23 @@ function FlowRenderer({
: null;
const flowEdges: Edge[] = data.links.map((link, idx) => {
const targetNode = data.nodes[link.target];
+ const sourceNode = data.nodes[link.source];
const isToProxy = targetNode?.nodeType === "proxy";
const isDimmed = activeLinkSet ? !activeLinkSet.has(idx) : false;
+ const isZeroTraffic = !!(
+ (sourceNode as any)?._zeroTraffic || (targetNode as any)?._zeroTraffic
+ );
return {
id: `e-${link.source}-${link.target}`,
source: String(link.source),
target: String(link.target),
type: "mergedAnimatedFlow",
- data: { isToProxy, dimmed: isDimmed, showAll },
+ data: {
+ isToProxy,
+ dimmed: isDimmed,
+ showAll,
+ _zeroTraffic: isZeroTraffic,
+ },
};
});
@@ -526,8 +539,7 @@ function FlowRenderer({
zoomOnScroll={false}
panOnScroll={false}
zoomOnDoubleClick={false}
- className="chain-flow-graph"
- >
+ className="chain-flow-graph">
<Background color={isDark ? "#374151" : "#e5e7eb"} gap={20} size={1} />
<Controls showInteractive={false} />
</ReactFlow>
@@ -545,6 +557,9 @@ export function UnifiedRuleChainFlow({
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [showAll, setShowAll] = useState(false);
+ const [activePolicyOnly, setActivePolicyOnly] = useState(false);
+ const [activeChainInfo, setActiveChainInfo] =
+ useState<ActiveChainInfo | null>(null);
const prevRuleRef = useRef(selectedRule);
// Initial fetch + background polling every 5 seconds
@@ -585,6 +600,35 @@ export function UnifiedRuleChainFlow({
};
}, [activeBackendId]);
+ // Fetch active chain info when activePolicyOnly is ON
+ useEffect(() => {
+ if (!activePolicyOnly) {
+ setActiveChainInfo(null);
+ return;
+ }
+ let cancelled = false;
+
+ async function fetchActiveChains() {
+ try {
+ const [providers, rules] = await Promise.all([
+ api.getClashProviders(activeBackendId),
+ api.getClashRules(activeBackendId),
+ ]);
+ if (cancelled) return;
+ setActiveChainInfo(resolveActiveChains(providers, rules));
+ } catch {
+ if (!cancelled) setActivePolicyOnly(false);
+ }
+ }
+
+ fetchActiveChains();
+ const interval = setInterval(fetchActiveChains, 10000);
+ return () => {
+ cancelled = true;
+ clearInterval(interval);
+ };
+ }, [activePolicyOnly, activeBackendId]);
+
// When user selects a different rule, auto-disable showAll
useEffect(() => {
if (selectedRule && selectedRule !== prevRuleRef.current) {
@@ -593,16 +637,151 @@ export function UnifiedRuleChainFlow({
}
}, [selectedRule]);
+ // Filter DAG when activePolicyOnly is ON
+ const filteredData = useMemo((): AllChainFlowData | null => {
+ if (!data) return null;
+ if (!activePolicyOnly || !activeChainInfo) return data;
+
+ const { activeNodeNames, activeLinkKeys, activeChains } = activeChainInfo;
+
+ // Build name→index map of existing nodes
+ const existingNodeMap = new Map<string, number>();
+ data.nodes.forEach((n, i) => existingNodeMap.set(n.name, i));
+
+ // Determine which existing nodes are active
+ const keepNodeIndices = new Set<number>();
+ for (const [, idx] of existingNodeMap) {
+ if (activeNodeNames.has(data.nodes[idx].name)) {
+ keepNodeIndices.add(idx);
+ }
+ }
+
+ // Build new nodes array (existing active + zero-traffic for missing)
+ const newNodes: MergedChainNode[] = [];
+ const nameToNewIdx = new Map<string, number>();
+
+ // First: existing active nodes
+ for (const idx of keepNodeIndices) {
+ const node = data.nodes[idx];
+ nameToNewIdx.set(node.name, newNodes.length);
+ newNodes.push({ ...node });
+ }
+
+ // Second: add zero-traffic nodes for active chain members not in existing data
+ for (const [, chain] of activeChains) {
+ for (let i = 0; i < chain.length; i++) {
+ const name = chain[i];
+ if (!nameToNewIdx.has(name)) {
+ const nodeType: "rule" | "group" | "proxy" =
+ i === 0 ? "rule" : i === chain.length - 1 ? "proxy" : "group";
+ nameToNewIdx.set(name, newNodes.length);
+ newNodes.push({
+ name,
+ layer: i,
+ nodeType,
+ totalUpload: 0,
+ totalDownload: 0,
+ totalConnections: 0,
+ rules: [],
+ _zeroTraffic: true,
+ } as MergedChainNode & { _zeroTraffic?: boolean } as any);
+ }
+ }
+ }
+
+ // Build new links
+ const newLinks: Array<{ source: number; target: number; rules: string[] }> =
+ [];
+ const linkKeySet = new Set<string>();
+
+ // Existing active links
+ for (const link of data.links) {
+ const srcName = data.nodes[link.source]?.name;
+ const tgtName = data.nodes[link.target]?.name;
+ if (srcName && tgtName && activeLinkKeys.has(`${srcName}|${tgtName}`)) {
+ const newSrc = nameToNewIdx.get(srcName);
+ const newTgt = nameToNewIdx.get(tgtName);
+ if (newSrc !== undefined && newTgt !== undefined) {
+ const key = `${newSrc}-${newTgt}`;
+ if (!linkKeySet.has(key)) {
+ linkKeySet.add(key);
+ newLinks.push({
+ source: newSrc,
+ target: newTgt,
+ rules: link.rules,
+ });
+ }
+ }
+ }
+ }
+
+ // Zero-traffic links for active chains not yet covered
+ for (const [, chain] of activeChains) {
+ for (let i = 0; i < chain.length - 1; i++) {
+ const srcIdx = nameToNewIdx.get(chain[i]);
+ const tgtIdx = nameToNewIdx.get(chain[i + 1]);
+ if (srcIdx !== undefined && tgtIdx !== undefined) {
+ const key = `${srcIdx}-${tgtIdx}`;
+ if (!linkKeySet.has(key)) {
+ linkKeySet.add(key);
+ newLinks.push({ source: srcIdx, target: tgtIdx, rules: [] });
+ }
+ }
+ }
+ }
+
+ // Rebuild rulePaths for the filtered data
+ const newRulePaths: Record<
+ string,
+ { nodeIndices: number[]; linkIndices: number[] }
+ > = {};
+ for (const [ruleName, chain] of activeChains) {
+ const nodeIndices: number[] = [];
+ const linkIndices: number[] = [];
+ for (const name of chain) {
+ const idx = nameToNewIdx.get(name);
+ if (idx !== undefined) nodeIndices.push(idx);
+ }
+ // Find link indices
+ for (let i = 0; i < chain.length - 1; i++) {
+ const srcIdx = nameToNewIdx.get(chain[i]);
+ const tgtIdx = nameToNewIdx.get(chain[i + 1]);
+ if (srcIdx !== undefined && tgtIdx !== undefined) {
+ const linkIdx = newLinks.findIndex(
+ (l) => l.source === srcIdx && l.target === tgtIdx,
+ );
+ if (linkIdx !== -1) linkIndices.push(linkIdx);
+ }
+ }
+ if (nodeIndices.length > 0) {
+ newRulePaths[ruleName] = { nodeIndices, linkIndices };
+ }
+ }
+
+ // Compute maxLayer
+ const maxLayer = newNodes.reduce((max, n) => Math.max(max, n.layer), 0);
+
+ return {
+ nodes: newNodes,
+ links: newLinks,
+ rulePaths: newRulePaths,
+ maxLayer,
+ };
+ }, [data, activePolicyOnly, activeChainInfo]);
+
+ // Use filteredData for rendering
+ const renderData = filteredData;
+
// Container height: compact for focused mode, taller for show-all
const containerHeight = useMemo(() => {
- if (!data || data.nodes.length === 0) return 280;
+ if (!renderData || renderData.nodes.length === 0) return 280;
- if (!showAll && selectedRule && data.rulePaths[selectedRule]) {
+ if (!showAll && selectedRule && renderData.rulePaths[selectedRule]) {
// Focused mode: just enough for the active chain
- const activeNodes = data.rulePaths[selectedRule].nodeIndices;
+ const activeNodes = renderData.rulePaths[selectedRule].nodeIndices;
const layerCounts = new Map<number, number>();
for (const idx of activeNodes) {
- const layer = data.nodes[idx].layer;
+ const layer = renderData.nodes[idx].layer;
layerCounts.set(layer, (layerCounts.get(layer) || 0) + 1);
}
const maxActiveInLayer =
@@ -612,12 +791,12 @@ export function UnifiedRuleChainFlow({
// Show-all mode: full height based on densest layer
const layerCounts = new Map<number, number>();
- data.nodes.forEach((node) => {
+ renderData.nodes.forEach((node) => {
layerCounts.set(node.layer, (layerCounts.get(node.layer) || 0) + 1);
});
const maxNodesInLayer = Math.max(...layerCounts.values());
return Math.min(600, Math.max(300, maxNodesInLayer * 90 + 60));
- }, [data, showAll, selectedRule]);
+ }, [renderData, showAll, selectedRule]);
if (loading) {
return (
@@ -632,7 +811,7 @@ export function UnifiedRuleChainFlow({
);
}
- if (error || !data || data.nodes.length <= 1) {
+ if (error || !renderData || renderData.nodes.length <= 1) {
return null;
}
@@ -644,25 +823,39 @@ export function UnifiedRuleChainFlow({
<Workflow className="h-4 w-4 text-primary" />
{t("chainFlow")}
</CardTitle>
- <Button
- variant={showAll ? "default" : "outline"}
- size="sm"
- className={cn(
- "h-7 px-3 text-xs gap-1.5 rounded-full",
- showAll && "bg-primary/90 hover:bg-primary"
- )}
- onClick={() => setShowAll(!showAll)}
- >
- <Eye className="h-3.5 w-3.5" />
- {t("showAll")}
- </Button>
+ <div className="flex items-center gap-2">
+ <Button
+ variant="outline"
+ size="sm"
+ className={cn(
+ "h-7 px-3 text-xs gap-1.5 rounded-full transition-colors",
+ activePolicyOnly
+ ? "border-emerald-500 text-emerald-600 bg-emerald-50 hover:bg-emerald-100 dark:text-emerald-400 dark:bg-emerald-500/10 dark:hover:bg-emerald-500/20 dark:border-emerald-500/50"
+ : "hover:border-emerald-300 hover:text-emerald-600",
+ )}
+ onClick={() => setActivePolicyOnly(!activePolicyOnly)}>
+ <Activity className={cn("h-3.5 w-3.5", activePolicyOnly && "text-emerald-500")} />
+ {t("activePolicy")}
+ </Button>
+ <Button
+ variant={showAll ? "default" : "outline"}
+ size="sm"
+ className={cn(
+ "h-7 px-3 text-xs gap-1.5 rounded-full",
+ showAll && "bg-primary/90 hover:bg-primary",
+ )}
+ onClick={() => setShowAll(!showAll)}>
+ <Eye className="h-3.5 w-3.5" />
+ {t("showAll")}
+ </Button>
+ </div>
</div>
</CardHeader>
<CardContent className="pt-0">
<div style={{ height: containerHeight }} className="w-full">
<ReactFlowProvider>
<FlowRenderer
- data={data}
+ data={renderData}
selectedRule={showAll ? null : selectedRule}
showAll={showAll}
/>
diff --git a/apps/web/components/stats-cards.tsx b/apps/web/components/stats-cards.tsx
index 2e07010..d141958 100644
--- a/apps/web/components/stats-cards.tsx
+++ b/apps/web/components/stats-cards.tsx
@@ -70,7 +70,7 @@ function StatCard({
color: string;
}) {
return (
- <div className="rounded-xl p-4 border bg-card flex flex-col">
+ <div className="rounded-xl p-4 border bg-card shadow-xs flex flex-col">
<div
className="w-10 h-10 rounded-lg flex items-center justify-center mb-3"
style={{ backgroundColor: `${color}15` }}
@@ -112,7 +112,7 @@ function AnimatedStatCard({
color: string;
}) {
return (
- <div className="rounded-xl p-4 border bg-card flex flex-col">
+ <div className="rounded-xl p-4 border bg-card shadow-xs flex flex-col">
<div
className="w-10 h-10 rounded-lg flex items-center justify-center mb-3"
style={{ backgroundColor: `${color}15` }}
@@ -177,7 +177,7 @@ function CircularProgressCard({
}, [targetOffset, motionOffset]);
return (
- <div className="rounded-xl p-4 border bg-card flex flex-col">
+ <div className="rounded-xl p-4 border bg-card shadow-xs flex flex-col">
<div className="mb-3">
<div className="relative" style={{ width: size, height: size }}>
<svg width={size} height={size} className="transform -rotate-90">
@@ -238,7 +238,7 @@ function TodayCard({
uploadLabel: string;
}) {
return (
- <div className="rounded-xl p-4 border bg-card flex flex-col">
+ <div className="rounded-xl p-4 border bg-card shadow-xs flex flex-col">
<div
className="w-10 h-10 rounded-lg flex items-center justify-center mb-3"
style={{ backgroundColor: "#10B98115" }}
diff --git a/apps/web/components/traffic-trend-chart.tsx b/apps/web/components/traffic-trend-chart.tsx
index 470ea6c..6232d3c 100644
--- a/apps/web/components/traffic-trend-chart.tsx
+++ b/apps/web/components/traffic-trend-chart.tsx
@@ -165,8 +165,33 @@ export const TrafficTrendChart = React.memo(function TrafficTrendChart({
</div>
</div>
- {/* Stats summary */}
- <div className="flex items-center gap-6 mt-3 text-xs">
+ {/* Stats summary - Mobile: card layout, Desktop: inline layout */}
+ {/* Mobile layout */}
+ <div className="grid grid-cols-3 gap-2 mt-2 lg:hidden">
+ <div className="flex flex-col items-center py-1.5 px-1 rounded-md bg-secondary/50 border border-border/50">
+ <span className="text-[9px] text-muted-foreground flex items-center gap-0.5">
+ <Clock className="w-2.5 h-2.5" />
+ {t("totalDownload")}
+ </span>
+ <span className="text-xs font-semibold tabular-nums">{formatBytes(stats.totalDownload)}</span>
+ </div>
+ <div className="flex flex-col items-center py-1.5 px-1 rounded-md bg-secondary/50 border border-border/50">
+ <span className="text-[9px] text-muted-foreground flex items-center gap-0.5">
+ <BarChart3 className="w-2.5 h-2.5" />
+ {t("totalUpload")}
+ </span>
+ <span className="text-xs font-semibold tabular-nums">{formatBytes(stats.totalUpload)}</span>
+ </div>
+ <div className="flex flex-col items-center py-1.5 px-1 rounded-md bg-secondary/50 border border-border/50">
+ <span className="text-[9px] text-muted-foreground flex items-center gap-0.5">
+ <Activity className="w-2.5 h-2.5" />
+ {t("total")}
+ </span>
+ <span className="text-xs font-bold tabular-nums">{formatBytes(stats.totalDownload + stats.totalUpload)}</span>
+ </div>
+ </div>
+ {/* Desktop layout */}
+ <div className="hidden lg:flex items-center gap-6 mt-3 text-xs">
<div className="flex items-center gap-1.5">
<Clock className="w-3.5 h-3.5 text-muted-foreground" />
<span className="text-muted-foreground">{t("totalDownload")}:</span>
diff --git a/apps/web/components/ui/card.tsx b/apps/web/components/ui/card.tsx
index 019e9c8..0b5a090 100644
--- a/apps/web/components/ui/card.tsx
+++ b/apps/web/components/ui/card.tsx
@@ -7,7 +7,7 @@ function Card({ className, ...props }: React.ComponentProps<"div">) {
<div
data-slot="card"
className={cn(
- "bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",
+ "bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-xs",
className
)}
{...props}
diff --git a/apps/web/lib/active-chain.ts b/apps/web/lib/active-chain.ts
new file mode 100644
index 0000000..0e31664
--- /dev/null
+++ b/apps/web/lib/active-chain.ts
@@ -0,0 +1,87 @@
+import type { ClashProvidersResponse, ClashRulesResponse } from "./api";
+
+export interface ActiveChainInfo {
+ /** Set of node names that are part of active chains */
+ activeNodeNames: Set<string>;
+ /** Set of "sourceName|targetName" keys for active links */
+ activeLinkKeys: Set<string>;
+ /** Map from proxy group name to its full active chain path */
+ activeChains: Map<string, string[]>;
+}
+
+/**
+ * Build a map of group name → currently selected proxy/group name
+ * from the providers/proxies response.
+ */
+function buildGroupNowMap(providers: ClashProvidersResponse): Map<string, string> {
+ const map = new Map<string, string>();
+ for (const provider of Object.values(providers.providers)) {
+ if (!provider.proxies) continue;
+ for (const proxy of provider.proxies) {
+ if (proxy.now) {
+ map.set(proxy.name, proxy.now);
+ }
+ }
+ }
+ return map;
+}
+
+/**
+ * Follow the active proxy chain from a starting group name.
+ * Returns the full path including the starting group.
+ */
+function followChain(startGroup: string, groupNowMap: Map<string, string>): string[] {
+ const path: string[] = [startGroup];
+ const visited = new Set<string>();
+ visited.add(startGroup);
+
+ let current = startGroup;
+ while (groupNowMap.has(current)) {
+ const next = groupNowMap.get(current)!;
+ if (visited.has(next)) break; // prevent cycles
+ visited.add(next);
+ path.push(next);
+ current = next;
+ }
+ return path;
+}
+
+/**
+ * Resolve active policy chains from Clash providers and rules data.
+ *
+ * Uses the target proxy group name (rule.proxy) as the chain start,
+ * NOT the internal rule type+payload (e.g. "RuleSet,netflix").
+ * This matches how traffic data stores rule names (by proxy group).
+ * Multiple low-level rules can target the same proxy group, so we deduplicate.
+ */
+export function resolveActiveChains(
+ providers: ClashProvidersResponse,
+ rules: ClashRulesResponse
+): ActiveChainInfo {
+ const groupNowMap = buildGroupNowMap(providers);
+ const activeNodeNames = new Set<string>();
+ const activeLinkKeys = new Set<string>();
+ const activeChains = new Map<string, string[]>();
+
+ const processedGroups = new Set<string>();
+
+ for (const rule of rules.rules) {
+ const targetGroup = rule.proxy;
+ if (processedGroups.has(targetGroup)) continue;
+ processedGroups.add(targetGroup);
+
+ // Build chain from the target proxy group: [group, now, now, ..., terminal]
+ const chain = followChain(targetGroup, groupNowMap);
+
+ activeChains.set(targetGroup, chain);
+
+ for (const name of chain) {
+ activeNodeNames.add(name);
+ }
+ for (let i = 0; i < chain.length - 1; i++) {
+ activeLinkKeys.add(`${chain[i]}|${chain[i + 1]}`);
+ }
+ }
+
+ return { activeNodeNames, activeLinkKeys, activeChains };
+}
diff --git a/apps/web/lib/api.ts b/apps/web/lib/api.ts
index d5f7d8c..d2fc50d 100644
--- a/apps/web/lib/api.ts
+++ b/apps/web/lib/api.ts
@@ -81,6 +81,36 @@ export interface Backend {
updated_at: string;
}
+export interface ClashProviderProxy {
+ alive: boolean;
+ name: string;
+ type: string;
+ now?: string;
+ all?: string[];
+ history?: Array<{ time: string; delay: number }>;
+}
+
+export interface ClashProvider {
+ name: string;
+ type: string;
+ vehicleType: string;
+ proxies: ClashProviderProxy[];
+}
+
+export interface ClashProvidersResponse {
+ providers: Record<string, ClashProvider>;
+}
+
+export interface ClashRule {
+ type: string;
+ payload: string;
+ proxy: string;
+}
+
+export interface ClashRulesResponse {
+ rules: ClashRule[];
+}
+
function buildUrl(base: string, params: Record<string, string | number | undefined>): string {
// Use simple URL construction for client-side relative URLs
const searchParams = new URLSearchParams();
@@ -240,6 +270,12 @@ export const api = {
buildUrl(`${API_BASE}/stats/rules/chain-flow-all`, { backendId })
),
+ getClashProviders: (backendId?: number) =>
+ fetchJson<ClashProvidersResponse>(buildUrl(`${API_BASE}/clash/providers/proxies`, { backendId })),
+
+ getClashRules: (backendId?: number) =>
+ fetchJson<ClashRulesResponse>(buildUrl(`${API_BASE}/clash/rules`, { backendId })),
+
search: (q: string) =>
fetchJson<DomainStats[]>(
`${API_BASE}/search?q=${encodeURIComponent(q)}`
diff --git a/apps/web/messages/en.json b/apps/web/messages/en.json
index d70bdc6..3b58e5e 100644
--- a/apps/web/messages/en.json
+++ b/apps/web/messages/en.json
@@ -179,7 +179,9 @@
"upload": "Upload",
"chainFlow": "Rule Chain Flow",
"loadingChainFlow": "Loading chain flow...",
- "showAll": "Show All"
+ "showAll": "Panorama",
+ "activePolicy": "All Policies",
+ "noTrafficRecord": "No traffic record"
},
"network": {
"title": "Network",
diff --git a/apps/web/messages/zh.json b/apps/web/messages/zh.json
index 731963a..b0307ec 100644
--- a/apps/web/messages/zh.json
+++ b/apps/web/messages/zh.json
@@ -178,7 +178,9 @@
"upload": "上传",
"chainFlow": "规则链路流向",
"loadingChainFlow": "加载链路流向...",
- "showAll": "显示全部"
+ "showAll": "全景展示",
+ "activePolicy": "全部策略",
+ "noTrafficRecord": "暂无流量记录"
},
"network": {
"title": "网络",
diff --git a/package.json b/package.json
index eea0ab5..35b08d4 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "clash-master",
- "version": "1.0.8",
+ "version": "1.0.9",
"private": true,
"workspaces": [
"apps/*",