]> OzVa Git service - ozva-cloud/commitdiff
feat: show precise file size with decimal (#210)
authorJesse Hu <jessehubj@163.com>
Thu, 18 May 2023 04:01:02 +0000 (12:01 +0800)
committerGitHub <noreply@github.com>
Thu, 18 May 2023 04:01:02 +0000 (12:01 +0800)
assets/index.js

index 7b99784632b255132a3a6350451d1be3edc059dd..54c3ed4f9a63d4401203fce863b2c0c072d2a5b6 100644 (file)
@@ -778,7 +778,11 @@ function formatSize(size) {
   const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
   if (size == 0) return [0, "B"];
   const i = parseInt(Math.floor(Math.log(size) / Math.log(1024)));
-  return [Math.round(size / Math.pow(1024, i), 2), sizes[i]];
+  ratio = 1
+  if (i >= 3) {
+    ratio = 100
+  }
+  return [Math.round(size * ratio / Math.pow(1024, i), 2) / ratio, sizes[i]];
 }
 
 function formatDuration(seconds) {
@@ -818,4 +822,4 @@ function getEncoding(contentType) {
       }
     }
     return 'utf-8'
-}
\ No newline at end of file
+}