From 597821b3bb3d3307096783daba4d7e3575897d08 Mon Sep 17 00:00:00 2001 From: Cubxity <27609129+Cubxity@users.noreply.github.com> Date: Mon, 10 Oct 2022 00:09:24 +0200 Subject: [PATCH] fix: byte units (#4419) --- .../components/server/console/StatGraphs.tsx | 2 +- resources/scripts/lib/formatters.spec.ts | 32 +++++++++---------- resources/scripts/lib/formatters.ts | 2 +- .../views/admin/servers/view/index.blade.php | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/resources/scripts/components/server/console/StatGraphs.tsx b/resources/scripts/components/server/console/StatGraphs.tsx index 4c17efe13..9af405ba6 100644 --- a/resources/scripts/components/server/console/StatGraphs.tsx +++ b/resources/scripts/components/server/console/StatGraphs.tsx @@ -17,7 +17,7 @@ export default () => { const previous = useRef>({ tx: -1, rx: -1 }); const cpu = useChartTickLabel('CPU', limits.cpu, '%', 2); - const memory = useChartTickLabel('Memory', limits.memory, 'MB'); + const memory = useChartTickLabel('Memory', limits.memory, 'MiB'); const network = useChart('Network', { sets: 2, options: { diff --git a/resources/scripts/lib/formatters.spec.ts b/resources/scripts/lib/formatters.spec.ts index 4907df7cf..c03008971 100644 --- a/resources/scripts/lib/formatters.spec.ts +++ b/resources/scripts/lib/formatters.spec.ts @@ -21,22 +21,22 @@ describe('@/lib/formatters.ts', function () { [100.998, '101 Bytes'], [512, '512 Bytes'], [1000, '1000 Bytes'], - [1024, '1 KB'], - [5068, '4.95 KB'], - [10_000, '9.77 KB'], - [10_240, '10 KB'], - [11_864, '11.59 KB'], - [1_000_000, '976.56 KB'], - [1_024_000, '1000 KB'], - [1_025_000, '1000.98 KB'], - [1_048_576, '1 MB'], - [1_356_000, '1.29 MB'], - [1_000_000_000, '953.67 MB'], - [1_070_000_100, '1020.43 MB'], - [1_073_741_824, '1 GB'], - [1_678_342_000, '1.56 GB'], - [1_000_000_000_000, '931.32 GB'], - [1_099_511_627_776, '1 TB'], + [1024, '1 KiB'], + [5068, '4.95 KiB'], + [10_000, '9.77 KiB'], + [10_240, '10 KiB'], + [11_864, '11.59 KiB'], + [1_000_000, '976.56 KiB'], + [1_024_000, '1000 KiB'], + [1_025_000, '1000.98 KiB'], + [1_048_576, '1 MiB'], + [1_356_000, '1.29 MiB'], + [1_000_000_000, '953.67 MiB'], + [1_070_000_100, '1020.43 MiB'], + [1_073_741_824, '1 GiB'], + [1_678_342_000, '1.56 GiB'], + [1_000_000_000_000, '931.32 GiB'], + [1_099_511_627_776, '1 TiB'], ])('should format %d bytes as "%s"', function (input, output) { expect(bytesToString(input)).toBe(output); }); diff --git a/resources/scripts/lib/formatters.ts b/resources/scripts/lib/formatters.ts index f68bbe3ab..66e4ea646 100644 --- a/resources/scripts/lib/formatters.ts +++ b/resources/scripts/lib/formatters.ts @@ -20,7 +20,7 @@ function bytesToString(bytes: number, decimals = 2): string { const i = Math.floor(Math.log(bytes) / Math.log(k)); const value = Number((bytes / Math.pow(k, i)).toFixed(decimals)); - return `${value} ${['Bytes', 'KB', 'MB', 'GB', 'TB'][i]}`; + return `${value} ${['Bytes', 'KiB', 'MiB', 'GiB', 'TiB'][i]}`; } /** diff --git a/resources/views/admin/servers/view/index.blade.php b/resources/views/admin/servers/view/index.blade.php index 4e8078ef8..e246b6cd3 100644 --- a/resources/views/admin/servers/view/index.blade.php +++ b/resources/views/admin/servers/view/index.blade.php @@ -101,7 +101,7 @@ @if($server->disk === 0) Unlimited @else - {{ $server->disk }}MB + {{ $server->disk }}MiB @endif