Skip to content

Commit

Permalink
luci: optimize xhttp_extra remove code
Browse files Browse the repository at this point in the history
  • Loading branch information
lwb1978 committed Jan 12, 2025
1 parent 6924065 commit 7866380
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -566,14 +566,12 @@ o = s:option(Value, _n("xhttp_path"), translate("XHTTP Path"))
o.placeholder = "/"
o:depends({ [_n("transport")] = "xhttp" })

o = s:option(TextValue, _n("xhttp_extra"), translate("XHTTP Extra"), translate("An <a target='_blank' href='https://xtls.github.io/config/transports/splithttp.html#extra'>XHTTP extra object</a> in raw json"))
o = s:option(TextValue, _n("xhttp_extra"), translate("XHTTP Extra"), translate("An XHttpObject in JSON format, used for sharing."))
o:depends({ [_n("transport")] = "xhttp" })
o.rows = 15
o.wrap = "off"
o.custom_write = function(self, section, value)

m:set(section, self.option:sub(1 + #option_prefix), value)

local success, data = pcall(jsonc.parse, value)
if success and data then
local address = (data.extra and data.extra.downloadSettings and data.extra.downloadSettings.address)
Expand All @@ -594,6 +592,10 @@ o.validate = function(self, value)
end
return value
end
o.custom_remove = function(self, section, value)
m:del(section, self.option:sub(1 + #option_prefix))
m:del(section, "download_address")
end

-- [[ Mux.Cool ]]--
o = s:option(Flag, _n("mux"), "Mux", translate("Enable Mux.Cool"))
Expand Down
13 changes: 9 additions & 4 deletions luci-app-passwall/luasrc/passwall/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1178,11 +1178,16 @@ function luci_types(id, m, s, type_name, option_prefix)
end
s.fields[key].remove = function(self, section)
if s.fields["type"]:formvalue(id) == type_name then
if self.rewrite_option and rewrite_option_table[self.rewrite_option] == 1 then
m:del(section, self.rewrite_option)
-- 添加自定义 custom_remove 属性,如果有自定义的 custom_remove 函数,则使用自定义的 remove 逻辑
if self.custom_remove then
self:custom_remove(section)
else
if self.option:find(option_prefix) == 1 then
m:del(section, self.option:sub(1 + #option_prefix))
if self.rewrite_option and rewrite_option_table[self.rewrite_option] == 1 then
m:del(section, self.rewrite_option)
else
if self.option:find(option_prefix) == 1 then
m:del(section, self.option:sub(1 + #option_prefix))
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions luci-app-passwall/po/zh-cn/passwall.po
Original file line number Diff line number Diff line change
Expand Up @@ -1567,8 +1567,8 @@ msgstr "客户端文件不适合当前设备。"
msgid "Can't move new file to path: %s"
msgstr "无法移动新文件到:%s"

msgid "An <a target='_blank' href='https://xtls.github.io/config/transports/splithttp.html#extra'>XHTTP extra object</a> in raw json"
msgstr "一个 json 格式的 <a target='_blank' href='https://xtls.github.io/config/transports/splithttp.html#extra'>XHTTP extra object</a>"
msgid "An XHttpObject in JSON format, used for sharing."
msgstr "JSON 格式的 XHttpObject,用来实现分享。"

msgid "Enable Mux.Cool"
msgstr "启用 Mux.Cool"
Expand Down

0 comments on commit 7866380

Please sign in to comment.