luci: optimize subscribe logic
This commit is contained in:
parent
8848f801b6
commit
1fc1e41f41
@ -1018,12 +1018,17 @@ local function select_node(nodes, config)
|
|||||||
end
|
end
|
||||||
-- 还不行 随便找一个
|
-- 还不行 随便找一个
|
||||||
if not server then
|
if not server then
|
||||||
server = uci:get_all(appname, '@' .. "nodes" .. '[0]')
|
local nodes_table = {}
|
||||||
if server then
|
for k, e in ipairs(api.get_valid_nodes()) do
|
||||||
if config.log == nil or config.log == true then
|
if e.node_type == "normal" then
|
||||||
log('【' .. config.remarks .. '】' .. '无法找到最匹配的节点,当前已更换为:' .. server.remarks)
|
nodes_table[#nodes_table + 1] = e
|
||||||
end
|
end
|
||||||
server = server[".name"]
|
end
|
||||||
|
if #nodes_table > 0 then
|
||||||
|
if config.log == nil or config.log == true then
|
||||||
|
log('【' .. config.remarks .. '】' .. '无法找到最匹配的节点,当前已更换为:' .. nodes_table[1].remarks)
|
||||||
|
end
|
||||||
|
server = nodes_table[1][".name"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if server then
|
if server then
|
||||||
@ -1037,15 +1042,15 @@ local function update_node(manual)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local group = ""
|
local group = {}
|
||||||
for _, v in ipairs(nodeResult) do
|
for _, v in ipairs(nodeResult) do
|
||||||
group = group .. v["remark"]
|
group[v["remark"]] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if manual == 0 and #group > 0 then
|
if manual == 0 and next(group) then
|
||||||
uci:foreach(appname, "nodes", function(node)
|
uci:foreach(appname, "nodes", function(node)
|
||||||
-- 如果是未发现新节点或手动导入的节点就不要删除了...
|
-- 如果未发现新节点或手动导入的节点就不要删除了...
|
||||||
if (node.add_from and group:find(node.add_from, 1, true)) and node.add_mode == "2" then
|
if node.add_mode == "2" and (node.add_from and group[node.add_from] == true) then
|
||||||
uci:delete(appname, node['.name'])
|
uci:delete(appname, node['.name'])
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@ -1246,7 +1251,7 @@ local execute = function()
|
|||||||
|
|
||||||
if #fail_list > 0 then
|
if #fail_list > 0 then
|
||||||
for index, value in ipairs(fail_list) do
|
for index, value in ipairs(fail_list) do
|
||||||
log(value.remark .. '订阅失败,可能是订阅地址失效,或是网络问题,请诊断!')
|
log(string.format('【%s】订阅失败,可能是订阅地址失效,或是网络问题,请诊断!', value.remark))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
update_node(0)
|
update_node(0)
|
||||||
|
Loading…
Reference in New Issue
Block a user