From 420c1d90074b5d4953248af177766bb2860c0297 Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Tue, 3 Dec 2024 15:44:46 +0800 Subject: [PATCH] feat: live speed --- src/components/ServerOverview.tsx | 43 ++++++++++++++++++++++-------- src/locales/en/translation.json | 3 ++- src/locales/zh-CN/translation.json | 3 ++- src/locales/zh-TW/translation.json | 3 ++- src/pages/Server.tsx | 19 +++++++++++++ 5 files changed, 57 insertions(+), 14 deletions(-) diff --git a/src/components/ServerOverview.tsx b/src/components/ServerOverview.tsx index dd6b0c1..9260e25 100644 --- a/src/components/ServerOverview.tsx +++ b/src/components/ServerOverview.tsx @@ -2,6 +2,7 @@ import { Card, CardContent } from "@/components/ui/card"; import { cn } from "@/lib/utils"; import { useTranslation } from "react-i18next"; import { formatBytes } from "@/lib/format"; +import { Separator } from "./ui/separator"; type ServerOverviewProps = { online: number; @@ -9,6 +10,8 @@ type ServerOverviewProps = { total: number; up: number; down: number; + upSpeed: number; + downSpeed: number; }; export default function ServerOverview({ @@ -17,6 +20,8 @@ export default function ServerOverview({ total, up, down, + upSpeed, + downSpeed, }: ServerOverviewProps) { const { t } = useTranslation(); @@ -24,7 +29,7 @@ export default function ServerOverview({ <>
- +

{t("serverOverview.totalServers")} @@ -43,7 +48,7 @@ export default function ServerOverview({ " hover:ring-green-500 ring-1 ring-transparent transition-all", )} > - +

{t("serverOverview.onlineServers")} @@ -64,7 +69,7 @@ export default function ServerOverview({ " hover:ring-red-500 ring-1 ring-transparent transition-all", )} > - +

{t("serverOverview.offlineServers")} @@ -84,20 +89,36 @@ export default function ServerOverview({ " hover:ring-purple-500 ring-1 ring-transparent transition-all", )} > - +

-

- {t("serverOverview.totalBandwidth")} -

- -
-

+

+

+ {t("serverOverview.totalBandwidth")} +

+ +

+ {t("serverOverview.speed")} +

+
+
+

↑{formatBytes(up)}

-

+

↓{formatBytes(down)}

+
+

+ ↑{formatBytes(upSpeed)}/s +

+

+ ↓{formatBytes(downSpeed)}/s +

+
diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index 89d5d0d..b18370e 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -14,7 +14,8 @@ "totalServers": "Total Servers", "onlineServers": "Online Servers", "offlineServers": "Offline Servers", - "totalBandwidth": "Total Bandwidth" + "totalBandwidth": "Total Bandwidth", + "speed": "Speed" }, "serverCard": { "mem": "MEM", diff --git a/src/locales/zh-CN/translation.json b/src/locales/zh-CN/translation.json index cdf2b6d..76a29b7 100644 --- a/src/locales/zh-CN/translation.json +++ b/src/locales/zh-CN/translation.json @@ -14,7 +14,8 @@ "totalServers": "服务器总数", "onlineServers": "在线服务器", "offlineServers": "离线服务器", - "totalBandwidth": "总流量" + "totalBandwidth": "总流量", + "speed": "速率" }, "serverCard": { "mem": "内存", diff --git a/src/locales/zh-TW/translation.json b/src/locales/zh-TW/translation.json index 88a63a3..9759d1f 100644 --- a/src/locales/zh-TW/translation.json +++ b/src/locales/zh-TW/translation.json @@ -14,7 +14,8 @@ "totalServers": "總服務器", "onlineServers": "線上服務器", "offlineServers": "離線服務器", - "totalBandwidth": "總帶寬" + "totalBandwidth": "總帶寬", + "speed": "速率" }, "serverCard": { "mem": "內存", diff --git a/src/pages/Server.tsx b/src/pages/Server.tsx index 88342de..3d08418 100644 --- a/src/pages/Server.tsx +++ b/src/pages/Server.tsx @@ -103,6 +103,23 @@ export default function Servers() { 0, ) || 0; + const upSpeed = + nezhaWsData?.servers?.reduce( + (total, server) => + formatNezhaInfo(nezhaWsData.now, server).online + ? total + (server.state?.net_out_speed ?? 0) + : total, + 0, + ) || 0; + const downSpeed = + nezhaWsData?.servers?.reduce( + (total, server) => + formatNezhaInfo(nezhaWsData.now, server).online + ? total + (server.state?.net_in_speed ?? 0) + : total, + 0, + ) || 0; + const filteredServers = nezhaWsData?.servers?.filter((server) => { if (currentGroup === "All") return true; @@ -123,6 +140,8 @@ export default function Servers() { offline={offlineServers} up={up} down={down} + upSpeed={upSpeed} + downSpeed={downSpeed} />