feat: update download speed formatting to Mbps

This commit is contained in:
Hachi-R
2025-04-10 16:09:41 -03:00
parent d28bb825a3
commit 22e92eb8f6
2 changed files with 8 additions and 2 deletions

View File

@@ -15,7 +15,7 @@ import type {
StartGameDownloadPayload,
} from "@types";
import { useDate } from "./use-date";
import { formatBytes } from "@shared";
import { formatBytesToMbps } from "@shared";
export function useDownload() {
const { updateLibrary } = useLibrary();
@@ -100,7 +100,7 @@ export function useDownload() {
};
return {
downloadSpeed: `${formatBytes(lastPacket?.downloadSpeed ?? 0)}/s`,
downloadSpeed: formatBytesToMbps(lastPacket?.downloadSpeed ?? 0),
progress: formatDownloadProgress(lastPacket?.progress ?? 0),
lastPacket,
eta: calculateETA(),

View File

@@ -49,6 +49,12 @@ export const formatBytes = (bytes: number): string => {
return `${Math.trunc(formatedByte * 10) / 10} ${FORMAT[base]}`;
};
export const formatBytesToMbps = (bytesPerSecond: number): string => {
const bitsPerSecond = bytesPerSecond * 8;
const mbps = bitsPerSecond / (1024 * 1024);
return `${Math.trunc(mbps * 10) / 10} Mbps`;
};
export const pipe =
<T>(...fns: ((arg: T) => any)[]) =>
(arg: T) =>