Skip to content

Commit 8259e2d

Browse files
committed
fix #4371
1 parent a7fb5a4 commit 8259e2d

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

luci-app-openclash/luasrc/controller/openclash.lua

+37-10
Original file line numberDiff line numberDiff line change
@@ -680,38 +680,61 @@ function sub_info_get()
680680
if string.match(info, "expire=%d+") then
681681
day_expire = tonumber(string.sub(string.match(info, "expire=%d+"), 8, -1)) or nil
682682
end
683-
expire = os.date("%Y-%m-%d", day_expire) or "null"
684-
if day_expire and os.time() <= day_expire then
683+
684+
if day_expire and day_expire == 0 then
685+
expire = luci.i18n.translate("Long-term")
686+
elseif day_expire then
687+
expire = os.date("%Y-%m-%d", day_expire) or "null"
688+
else
689+
expire = "null"
690+
end
691+
692+
if day_expire and day_expire ~= 0 and os.time() <= day_expire then
685693
day_left = math.ceil((day_expire - os.time()) / (3600*24))
686694
if math.ceil(day_left / 365) > 50 then
687695
day_left = ""
688696
end
697+
elseif day_expire and day_expire == 0 then
698+
day_left = ""
689699
elseif day_expire == nil then
690700
day_left = "null"
691701
else
692702
day_left = 0
693703
end
694-
if used and total and used <= total then
695-
percent = string.format("%.1f",((total-used)/total)*100) or nil
696-
surplus = fs.filesize(total - used) or "null"
704+
705+
if used and total and used <= total and total > 0 then
706+
percent = string.format("%.1f",((total-used)/total)*100) or "100"
707+
surplus = fs.filesize(total - used)
708+
elseif used and total and used > total and total > 0 then
709+
percent = "0"
710+
surplus = "-"..fs.filesize(total - used)
711+
elseif used and total and used < total and total == 0.0 then
712+
percent = "0"
713+
surplus = fs.filesize(total - used)
714+
elseif used and total and used == total and total == 0.0 then
715+
percent = "0"
716+
surplus = "0.0 KB"
717+
elseif used and total and used > total and total == 0.0 then
718+
percent = "100"
719+
surplus = fs.filesize(total - used)
697720
elseif used == nil and total and total > 0.0 then
698721
percent = 100
699-
surplus = total
700-
elseif total and total == 0.0 then
722+
surplus = fs.filesize(total)
723+
elseif used == nil and total and total == 0.0 then
701724
percent = 100
702725
surplus = ""
703726
else
704727
percent = 0
705728
surplus = "null"
706729
end
707-
if total and total > 0.0 then
708-
total = fs.filesize(total) or "null"
730+
if total and total > 0 then
731+
total = fs.filesize(total)
709732
elseif total and total == 0.0 then
710733
total = ""
711734
else
712735
total = "null"
713736
end
714-
used = fs.filesize(used) or "null"
737+
used = fs.filesize(used)
715738
sub_info = "Successful"
716739
else
717740
sub_info = "No Sub Info Found"
@@ -1196,6 +1219,10 @@ function action_refresh_log()
11961219
if len == log_len then return nil end
11971220
if log_len == 0 then
11981221
if len > limit then lens = limit else lens = len end
1222+
elseif len - log_len > limit then
1223+
lens = limit
1224+
elseif len < log_len then
1225+
lens = len
11991226
else
12001227
lens = len - log_len
12011228
end

luci-app-openclash/luasrc/openclash.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,14 @@ end
261261
function filesize(e)
262262
local t=0
263263
local a={' KB',' MB',' GB',' TB',' PB'}
264+
if e < 0 then
265+
e = -e
266+
end
264267
repeat
265268
e=e/1024
266269
t=t+1
267270
until(e<=1024)
268-
return string.format("%.1f",e)..a[t]
271+
return string.format("%.1f",e)..a[t] or "0.0 KB"
269272
end
270273

271274
function lanip()

0 commit comments

Comments
 (0)