From 580a72e141266fc00b66986343a2e763d1a27224 Mon Sep 17 00:00:00 2001 From: VictoriousRaptor <10308169+VictoriousRaptor@users.noreply.github.com> Date: Sat, 18 Jan 2020 02:26:12 +0800 Subject: [PATCH] Update lua-app-filetransfer (#2688) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix #350 既然你都解决了干嘛不PR…… * Convert size in bytes to readable string * Fix kB --- .../luasrc/model/cbi/updownload.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/package/lean/luci-app-filetransfer/luasrc/model/cbi/updownload.lua b/package/lean/luci-app-filetransfer/luasrc/model/cbi/updownload.lua index 7b487cb21..af56b44b7 100644 --- a/package/lean/luci-app-filetransfer/luasrc/model/cbi/updownload.lua +++ b/package/lean/luci-app-filetransfer/luasrc/model/cbi/updownload.lua @@ -86,6 +86,16 @@ elseif luci.http.formvalue("download") then Download() end +local function getSizeStr(size) + local i = 0 + local byteUnits = {' kB', ' MB', ' GB', ' TB'} + repeat + size = size / 1024 + i = i + 1 + until(size <= 1024) + return string.format("%.1f", size) .. byteUnits[i] +end + local inits, attr = {} for i, f in ipairs(fs.glob("/tmp/upload/*")) do attr = fs.stat(f) @@ -94,7 +104,7 @@ for i, f in ipairs(fs.glob("/tmp/upload/*")) do inits[i].name = fs.basename(f) inits[i].mtime = os.date("%Y-%m-%d %H:%M:%S", attr.mtime) inits[i].modestr = attr.modestr - inits[i].size = tostring(attr.size) + inits[i].size = getSizeStr(attr.size) inits[i].remove = 0 inits[i].install = false end