feat: net transfer badge

This commit is contained in:
hamster1963
2024-11-30 22:26:13 +08:00
parent 48b2d1493a
commit 3f0c2ed39d
8 changed files with 61 additions and 48 deletions

View File

@@ -1,9 +1,19 @@
export function formatBytes(bytes: number, decimals = 2): string {
if (bytes === 0) return "0 B";
export function formatBytes(bytes: number, decimals: number = 2) {
if (!+bytes) return "0 Bytes";
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
const sizes = [
"Bytes",
"KiB",
"MiB",
"GiB",
"TiB",
"PiB",
"EiB",
"ZiB",
"YiB",
];
const i = Math.floor(Math.log(bytes) / Math.log(k));

View File

@@ -6,7 +6,7 @@ export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export function formatNezhaInfo(now: number,serverInfo: NezhaServer) {
export function formatNezhaInfo(now: number, serverInfo: NezhaServer) {
const lastActiveTime = parseISOTimestamp(serverInfo.last_active);
return {
...serverInfo,
@@ -27,28 +27,6 @@ export function formatNezhaInfo(now: number,serverInfo: NezhaServer) {
};
}
export function formatBytes(bytes: number, decimals: number = 2) {
if (!+bytes) return "0 Bytes";
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = [
"Bytes",
"KiB",
"MiB",
"GiB",
"TiB",
"PiB",
"EiB",
"ZiB",
"YiB",
];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
}
export function getDaysBetweenDates(date1: string, date2: string): number {
const oneDay = 24 * 60 * 60 * 1000; // 一天的毫秒数
const firstDate = new Date(date1);