Skip to content

Commit

Permalink
chore: hide yacd fetch log
Browse files Browse the repository at this point in the history
  • Loading branch information
vernesong committed Nov 13, 2021
1 parent da8913b commit 43192a3
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions luci-app-openclash/luasrc/controller/openclash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ function action_refresh_log()
luci.http.prepare_content("application/json")
local logfile="/tmp/openclash.log"
local file = io.open(logfile, "r+")
local info, len, line, lens, cache
local info, len, line, lens, cache, ex_match
local data = ""
local limit = 1000
local log_tb = {}
Expand All @@ -941,28 +941,40 @@ function action_refresh_log()
string.gsub(info, '[^\n]+', function(w) table.insert(log_tb, w) end, lens)
for i=1, lens do
line = log_tb[i]:reverse()
if not string.find (line, "level=") then
if not string.find (line, "") and not string.find (line, "") then
line = string.sub(line, 0, 20)..luci.i18n.translate(string.sub(line, 21, -1))
else
local a = string.find (line, "")
local b = string.find (line, "")+2
if a <= 21 then
line = string.sub(line, 0, b)..luci.i18n.translate(string.sub(line, b+1, -1))
elseif b < string.len(line) then
line = string.sub(line, 0, 20)..luci.i18n.translate(string.sub(line, 21, a-1))..string.sub(line, a, b)..luci.i18n.translate(string.sub(line, b+1, -1))
elseif b == string.len(line) then
line = string.sub(line, 0, 20)..luci.i18n.translate(string.sub(line, 21, a-1))..string.sub(line, a, b)
ex_match = false
while true do
ex_keys = {"^Sec%-Fetch%-Mode", "^User%-Agent", "^Access%-Control", "^Accept", "^Origin", "^Referer", "^Connection"}
for key=1, #ex_keys do
if string.find (line, ex_keys[key]) then
ex_match = true
break
end
end
if ex_match then break end
if not string.find (line, "level=") then
if not string.find (line, "") and not string.find (line, "") then
line = string.sub(line, 0, 20)..luci.i18n.translate(string.sub(line, 21, -1))
else
local a = string.find (line, "")
local b = string.find (line, "")+2
if a <= 21 then
line = string.sub(line, 0, b)..luci.i18n.translate(string.sub(line, b+1, -1))
elseif b < string.len(line) then
line = string.sub(line, 0, 20)..luci.i18n.translate(string.sub(line, 21, a-1))..string.sub(line, a, b)..luci.i18n.translate(string.sub(line, b+1, -1))
elseif b == string.len(line) then
line = string.sub(line, 0, 20)..luci.i18n.translate(string.sub(line, 21, a-1))..string.sub(line, a, b)
end
end
end
end
if data == "" then
data = line
elseif log_len == 0 and i == limit then
data = data .."\n" .. line .. "\n..."
else
data = data .."\n" .. line
end
end
if data == "" then
data = line
elseif log_len == 0 and i == limit then
data = data .."\n" .. line .. "\n..."
else
data = data .."\n" .. line
end
break
end
end
luci.http.write_json({
len = len,
Expand Down

0 comments on commit 43192a3

Please sign in to comment.