From cf365fc8db2c3b32f992218f6b1dda6524a8a4b7 Mon Sep 17 00:00:00 2001 From: Azalea Gui Date: Thu, 9 Feb 2023 18:40:28 -0500 Subject: [PATCH] [O] Format size --- src/App.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/App.tsx b/src/App.tsx index 2891f9e..3729d22 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,6 +4,11 @@ import { Component, createResource, createSignal, For, lazy, Show } from 'solid- const host = "https://daisy-ddns.hydev.org/data/api/OS" const fetchApi = async () => await (await fetch(host)).json() + +function sizeFmt(size: number) { + var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024)); + return (size / Math.pow(1024, i)).toFixed(1) + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i]; +} export default function App() { const [api] = createResource(fetchApi) @@ -17,7 +22,7 @@ export default function App() { {f.name} - {f.size} + {sizeFmt(f.size)} {moment(f.mtime).fromNow()}