diff --git a/src/components/ServerCardInline.tsx b/src/components/ServerCardInline.tsx index f650105..318f421 100644 --- a/src/components/ServerCardInline.tsx +++ b/src/components/ServerCardInline.tsx @@ -1,7 +1,12 @@ import ServerFlag from "@/components/ServerFlag"; import ServerUsageBar from "@/components/ServerUsageBar"; -import { cn, formatNezhaInfo } from "@/lib/utils"; +import { + cn, + formatNezhaInfo, + getDaysBetweenDates, + parsePublicNote, +} from "@/lib/utils"; import { NezhaServer } from "@/types/nezha-api"; import { Card } from "./ui/card"; import { useNavigate } from "react-router-dom"; @@ -35,10 +40,27 @@ export default function ServerCardInline({ uptime, net_in_transfer, net_out_transfer, + public_note, } = formatNezhaInfo(now, serverInfo); const showFlag = true; + const parsedData = parsePublicNote(public_note); + + let daysLeft = 0; + let isNeverExpire = false; + + if (parsedData?.billingDataMod?.endDate) { + if (parsedData.billingDataMod.endDate.startsWith("0000-00-00")) { + isNeverExpire = true; + } else { + daysLeft = getDaysBetweenDates( + parsedData.billingDataMod.endDate, + new Date().toISOString(), + ); + } + } + return online ? (
{showFlag ? : null} -
+

{name}

+ {parsedData && + (daysLeft >= 0 ? ( +

+ 剩余时间: {isNeverExpire ? "永久" : daysLeft + "天"} +

+ ) : ( +

+ 已过期: {daysLeft * -1} 天 +

+ ))}