From 9411b054f8ad47e34cec302c9dbea0ff32fbb2a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=82=88?= Date: Sun, 8 Oct 2017 03:52:43 +0800 Subject: [PATCH] change calculation of disk size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王邈 --- static/js/status.es6 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/static/js/status.es6 b/static/js/status.es6 index 1452d7b..d2c04bc 100644 --- a/static/js/status.es6 +++ b/static/js/status.es6 @@ -2,13 +2,21 @@ --- $(document).ready(() => { var mir_tmpl = $("#template").text(); - + function readableFileSize(size) { + var units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + var i = 0; + while(size >= 1024) { + size /= 1024; + ++i; + } + return size.toFixed(1) + ' ' + units[i]; + } $.get("/static/status/disk.json", (d) => { var used_percent = Math.round(d.used_kb * 100 / d.total_kb); $('#disk-usage-bar') .attr("aria-valuenow", used_percent) .css("width", used_percent + "%") - .html("" + d.used_readable + " / " + d.total_readable + ""); + .html("" + readableFileSize(d.used_kb * 1024) + " / " + readableFileSize(d.total_kb * 1024) + ""); }); window.refreshMirrorList = () => {