import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; import ServerFlag from "@/components/ServerFlag"; import ServerUsageBar from "@/components/ServerUsageBar"; import { formatBytes } from "@/lib/format"; import { GetFontLogoClass, GetOsName, MageMicrosoftWindows, } from "@/lib/logo-class"; import { cn, formatNezhaInfo, parsePublicNote } from "@/lib/utils"; import type { NezhaServer } from "@/types/nezha-api"; import BillingInfo from "./billingInfo"; import PlanInfo from "./PlanInfo"; import { Badge } from "./ui/badge"; import { Card } from "./ui/card"; export default function ServerCard({ now, serverInfo, }: { now: number; serverInfo: NezhaServer; }) { const { t } = useTranslation(); const navigate = useNavigate(); const { name, country_code, online, cpu, up, down, mem, stg, net_in_transfer, net_out_transfer, public_note, platform, } = formatNezhaInfo(now, serverInfo); const cardClick = () => { sessionStorage.setItem("fromMainPage", "true"); navigate(`/server/${serverInfo.id}`); }; const showFlag = true; const customBackgroundImage = (window.CustomBackgroundImage as string) !== "" ? window.CustomBackgroundImage : undefined; // @ts-expect-error ShowNetTransfer is a global variable const showNetTransfer = window.ShowNetTransfer as boolean; // @ts-expect-error FixedTopServerName is a global variable const fixedTopServerName = window.FixedTopServerName as boolean; const parsedData = parsePublicNote(public_note); return online ? ( {showFlag ? : null} {name} {parsedData?.billingDataMod && ( )} {parsedData?.billingDataMod && } {fixedTopServerName && ( {platform.includes("Windows") ? ( ) : ( )} {t("serverCard.system")} {platform.includes("Windows") ? "Windows" : GetOsName(platform)} )} {"CPU"} {cpu.toFixed(2)}% {t("serverCard.mem")} {mem.toFixed(2)}% {t("serverCard.stg")} {stg.toFixed(2)}% {t("serverCard.upload")} {up >= 1024 ? `${(up / 1024).toFixed(2)}G/s` : up >= 1 ? `${up.toFixed(2)}M/s` : `${(up * 1024).toFixed(2)}K/s`} {t("serverCard.download")} {down >= 1024 ? `${(down / 1024).toFixed(2)}G/s` : down >= 1 ? `${down.toFixed(2)}M/s` : `${(down * 1024).toFixed(2)}K/s`} {showNetTransfer && ( {t("serverCard.upload")}:{formatBytes(net_out_transfer)} {t("serverCard.download")}:{formatBytes(net_in_transfer)} )} {parsedData?.planDataMod && } ) : ( {showFlag ? : null} {name} {parsedData?.billingDataMod && ( )} {parsedData?.billingDataMod && } {parsedData?.planDataMod && } ); }
{name}
{t("serverCard.system")}
{"CPU"}
{t("serverCard.mem")}
{t("serverCard.stg")}
{t("serverCard.upload")}
{t("serverCard.download")}