diff --git a/app/(main)/ClientComponents/detail/ServerDetailClient.tsx b/app/(main)/ClientComponents/detail/ServerDetailClient.tsx index 2986438..d775d7a 100644 --- a/app/(main)/ClientComponents/detail/ServerDetailClient.tsx +++ b/app/(main)/ClientComponents/detail/ServerDetailClient.tsx @@ -6,7 +6,7 @@ import ServerFlag from "@/components/ServerFlag" import { ServerDetailLoading } from "@/components/loading/ServerDetailLoading" import { Badge } from "@/components/ui/badge" import { Card, CardContent } from "@/components/ui/card" -import { cn, formatBytes } from "@/lib/utils" +import { cn, formatBytes, formatNezhaInfo } from "@/lib/utils" import countries from "i18n-iso-countries" import enLocale from "i18n-iso-countries/langs/en.json" import { useTranslations } from "next-intl" @@ -45,9 +45,9 @@ export default function ServerDetailClient({ } const { data: serverList, error, isLoading } = useServerData() - const data = serverList?.result?.find((item) => item.id === server_id) + const serverData = serverList?.result?.find((item) => item.id === server_id) - if (!data && !isLoading) { + if (!serverData && !isLoading) { notFound() } @@ -62,7 +62,28 @@ export default function ServerDetailClient({ ) } - if (!data) return + if (!serverData) return + + const { + name, + online, + uptime, + version, + arch, + mem_total, + disk_total, + country_code, + platform, + platform_version, + cpu_info, + gpu_info, + load_1, + load_5, + load_15, + net_out_transfer, + net_in_transfer, + last_active_time_string, + } = formatNezhaInfo(serverData) return (
@@ -71,7 +92,7 @@ export default function ServerDetailClient({ className="flex flex-none cursor-pointer font-semibold leading-none items-center break-all tracking-tight gap-0.5 text-xl hover:opacity-50 transition-opacity duration-300" > - {data?.name} + {name}
@@ -82,12 +103,12 @@ export default function ServerDetailClient({ className={cn( "text-[9px] rounded-[6px] w-fit px-1 py-0 -mt-[0.3px] dark:text-white", { - " bg-green-800": data?.online_status, - " bg-red-600": !data?.online_status, + " bg-green-800": online, + " bg-red-600": !online, }, )} > - {data?.online_status ? t("Online") : t("Offline")} + {online ? t("Online") : t("Offline")}
@@ -98,29 +119,29 @@ export default function ServerDetailClient({

{t("Uptime")}

{" "} - {data?.status.Uptime / 86400 >= 1 - ? (data?.status.Uptime / 86400).toFixed(0) + " " + t("Days") - : (data?.status.Uptime / 3600).toFixed(0) + " " + t("Hours")}{" "} + {uptime / 86400 >= 1 + ? (uptime / 86400).toFixed(0) + " " + t("Days") + : (uptime / 3600).toFixed(0) + " " + t("Hours")}{" "}
- {data?.host.Version && ( + {version && (

{t("Version")}

-
{data?.host.Version}
+
{version}
)} - {data?.host.Arch && ( + {arch && (

{t("Arch")}

-
{data?.host.Arch}
+
{arch}
@@ -130,7 +151,7 @@ export default function ServerDetailClient({

{t("Mem")}

-
{formatBytes(data?.host.MemTotal)}
+
{formatBytes(mem_total)}
@@ -138,23 +159,18 @@ export default function ServerDetailClient({

{t("Disk")}

-
{formatBytes(data?.host.DiskTotal)}
+
{formatBytes(disk_total)}
- {data?.host.CountryCode && ( + {country_code && (

{t("Region")}

-
- {countries.getName(data?.host.CountryCode, "en")} -
- +
{countries.getName(country_code, "en")}
+
@@ -162,7 +178,7 @@ export default function ServerDetailClient({ )}
- {data?.host.Platform && ( + {platform && (
@@ -170,29 +186,29 @@ export default function ServerDetailClient({
{" "} - {data?.host.Platform} - {data?.host.PlatformVersion}{" "} + {platform} - {platform_version}{" "}
)} - {data?.host.CPU && ( + {cpu_info && cpu_info.length > 0 && (

{t("CPU")}

-
{data?.host.CPU.join(", ")}
+
{cpu_info.join(", ")}
)} - {data?.host.GPU && ( + {gpu_info && gpu_info.length > 0 && (

{"GPU"}

-
{data?.host.GPU.join(", ")}
+
{gpu_info.join(", ")}
@@ -204,8 +220,7 @@ export default function ServerDetailClient({

{t("Load")}

- {data.status.Load1.toFixed(2) || "0.00"} / {data.status.Load5.toFixed(2) || "0.00"}{" "} - / {data.status.Load15.toFixed(2) || "0.00"} + {load_1 || "0.00"} / {load_5 || "0.00"} / {load_15 || "0.00"}
@@ -214,8 +229,8 @@ export default function ServerDetailClient({

{t("Upload")}

- {data.status.NetOutTransfer ? ( -
{formatBytes(data.status.NetOutTransfer)}
+ {net_out_transfer ? ( +
{formatBytes(net_out_transfer)}
) : (
Unknown
)} @@ -226,8 +241,8 @@ export default function ServerDetailClient({

{t("Download")}

- {data.status.NetInTransfer ? ( -
{formatBytes(data.status.NetInTransfer)}
+ {net_in_transfer ? ( +
{formatBytes(net_in_transfer)}
) : (
Unknown
)} @@ -235,6 +250,18 @@ export default function ServerDetailClient({
+
+ + +
+

{t("LastActive")}

+
+ {last_active_time_string ? last_active_time_string : "N/A"} +
+
+
+
+
) } diff --git a/lib/utils.ts b/lib/utils.ts index bc35ce8..2c100d9 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -13,14 +13,32 @@ export function formatNezhaInfo(serverInfo: NezhaAPISafe) { process: serverInfo.status.ProcessCount || 0, up: serverInfo.status.NetOutSpeed / 1024 / 1024 || 0, down: serverInfo.status.NetInSpeed / 1024 / 1024 || 0, + last_active_time_string: serverInfo.last_active + ? new Date(serverInfo.last_active * 1000).toLocaleString() + : "", online: serverInfo.online_status, + uptime: serverInfo.status.Uptime || 0, + version: serverInfo.host.Version || null, tcp: serverInfo.status.TcpConnCount || 0, udp: serverInfo.status.UdpConnCount || 0, + arch: serverInfo.host.Arch || "", + mem_total: serverInfo.host.MemTotal || 0, + swap_total: serverInfo.host.SwapTotal || 0, + disk_total: serverInfo.host.DiskTotal || 0, + platform: serverInfo.host.Platform || "", + platform_version: serverInfo.host.PlatformVersion || "", mem: (serverInfo.status.MemUsed / serverInfo.host.MemTotal) * 100 || 0, swap: (serverInfo.status.SwapUsed / serverInfo.host.SwapTotal) * 100 || 0, disk: (serverInfo.status.DiskUsed / serverInfo.host.DiskTotal) * 100 || 0, stg: (serverInfo.status.DiskUsed / serverInfo.host.DiskTotal) * 100 || 0, + net_out_transfer: serverInfo.status.NetOutTransfer || 0, + net_in_transfer: serverInfo.status.NetInTransfer || 0, country_code: serverInfo.host.CountryCode, + cpu_info: serverInfo.host.CPU || [], + gpu_info: serverInfo.host.GPU || [], + load_1: serverInfo.status.Load1?.toFixed(2) || 0.0, + load_5: serverInfo.status.Load5?.toFixed(2) || 0.0, + load_15: serverInfo.status.Load15?.toFixed(2) || 0.0, } } diff --git a/messages/en.json b/messages/en.json index c0ebb5c..f1d1edf 100644 --- a/messages/en.json +++ b/messages/en.json @@ -85,7 +85,8 @@ "CPU": "CPU", "Upload": "Upload", "Download": "Download", - "Load": "Load" + "Load": "Load", + "LastActive": "Last Active" }, "ServerDetailChartClient": { "chart_fetch_error_message": "Please check your environment variables and review the server console", diff --git a/messages/ja.json b/messages/ja.json index 5394599..76fb128 100644 --- a/messages/ja.json +++ b/messages/ja.json @@ -85,7 +85,8 @@ "CPU": "CPU", "Load": "負荷", "Upload": "Upload", - "Download": "Download" + "Download": "Download", + "LastActive": "Last Active" }, "ServerDetailChartClient": { "chart_fetch_error_message": "環境変数を確認し、サーバーコンソールを確認してください", diff --git a/messages/zh-t.json b/messages/zh-t.json index fa89a82..477ae3f 100644 --- a/messages/zh-t.json +++ b/messages/zh-t.json @@ -85,7 +85,8 @@ "CPU": "CPU", "Upload": "上傳", "Download": "下載", - "Load": "負載" + "Load": "負載", + "LastActive": "最後上報時間" }, "ServerDetailChartClient": { "chart_fetch_error_message": "獲取伺服器詳情失敗,請檢查您的環境變數並檢查伺服器控制台", diff --git a/messages/zh.json b/messages/zh.json index fa92b84..6346934 100644 --- a/messages/zh.json +++ b/messages/zh.json @@ -85,7 +85,8 @@ "CPU": "CPU", "Upload": "上传", "Download": "下载", - "Load": "负载" + "Load": "负载", + "LastActive": "最后上报时间" }, "ServerDetailChartClient": { "chart_fetch_error_message": "获取服务器详情失败,请检查您的环境变量并检查服务器控制台",