From faed417e4408545b86aa70a5a1efbc1db0a9a5ef Mon Sep 17 00:00:00 2001 From: Gzxhwq Date: Mon, 16 Oct 2023 20:35:03 +0800 Subject: [PATCH] luci: fix hysteria2 bandwidth when nil (#2855) --- .../model/cbi/passwall/client/type/hysteria2.lua | 2 -- .../model/cbi/passwall/server/type/hysteria2.lua | 2 -- .../luasrc/passwall/util_hysteria2.lua | 16 ++++++++-------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/type/hysteria2.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/type/hysteria2.lua index 3ad4ca5c7..15d506d94 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/type/hysteria2.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/type/hysteria2.lua @@ -45,11 +45,9 @@ o = s:option(Flag, option_name("tls_allowInsecure"), translate("allowInsecure"), o.default = "0" o = s:option(Value, option_name("up_mbps"), translate("Max upload Mbps")) -o.default = "100" o.rewrite_option = o.option o = s:option(Value, option_name("down_mbps"), translate("Max download Mbps")) -o.default = "100" o.rewrite_option = o.option o = s:option(Value, option_name("hop_interval"), translate("Hop Interval")) diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/server/type/hysteria2.lua b/luci-app-passwall/luasrc/model/cbi/passwall/server/type/hysteria2.lua index 14fffb10a..ced737441 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/server/type/hysteria2.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/server/type/hysteria2.lua @@ -33,11 +33,9 @@ o.default = "1" o.rewrite_option = o.option o = s:option(Value, option_name("up_mbps"), translate("Max upload Mbps")) -o.default = "100" o.rewrite_option = o.option o = s:option(Value, option_name("down_mbps"), translate("Max download Mbps")) -o.default = "100" o.rewrite_option = o.option o = s:option(Flag, option_name("ignoreClientBandwidth"), translate("ignoreClientBandwidth")) diff --git a/luci-app-passwall/luasrc/passwall/util_hysteria2.lua b/luci-app-passwall/luasrc/passwall/util_hysteria2.lua index bf29fab4b..a96d1f2f2 100644 --- a/luci-app-passwall/luasrc/passwall/util_hysteria2.lua +++ b/luci-app-passwall/luasrc/passwall/util_hysteria2.lua @@ -20,10 +20,10 @@ function gen_config_server(node) type = "password", password = node.hysteria2_auth_password }, - bandwidth = { - up = node.hysteria2_up_mbps and node.hysteria2_up_mbps .. " mbps" or "1 gbps", - down = node.hysteria2_down_mbps and node.hysteria2_down_mbps .. " mbps" or "1 gbps", - }, + bandwidth = (node.hysteria2_up_mbps or node.hysteria2_down_mbps) and { + up = node.hysteria2_up_mbps and node.hysteria2_up_mbps .. " mbps" or nil, + down = node.hysteria2_down_mbps and node.hysteria2_down_mbps .. " mbps" or nil + } or nil, ignoreClientBandwidth = (node.hysteria2_ignoreClientBandwidth == "1") and true or false, disableUDP = (node.hysteria2_udp == "0") and true or false, } @@ -85,10 +85,10 @@ function gen_config(var) maxIdleTimeout = (node.hysteria2_idle_timeout) and tonumber(node.hysteria2_idle_timeout) or nil, disablePathMTUDiscovery = (node.hysteria2_disable_mtu_discovery) and true or false, }, - bandwidth = { - up = node.hysteria2_up_mbps and node.hysteria2_up_mbps .. " mbps" or "100 mbps", - down = node.hysteria2_down_mbps and node.hysteria2_down_mbps .. " mbps" or "100 mbps" - }, + bandwidth = (node.hysteria2_up_mbps or node.hysteria2_down_mbps) and { + up = node.hysteria2_up_mbps and node.hysteria2_up_mbps .. " mbps" or nil, + down = node.hysteria2_down_mbps and node.hysteria2_down_mbps .. " mbps" or nil + } or nil, fast_open = (node.fast_open == "1") and true or false, lazy = (node.hysteria2_lazy_start == "1") and true or false, socks5 = (local_socks_address and local_socks_port) and {