From 4787d821bd44fda6e10e92e4f8f765c99f470cd3 Mon Sep 17 00:00:00 2001 From: asdlokj1qpi23 Date: Sun, 27 Apr 2025 11:13:36 +0800 Subject: [PATCH] fix surge error,(#27) (#28) --- src/generator/config/subexport.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/generator/config/subexport.cpp b/src/generator/config/subexport.cpp index 8449cb6..d853edb 100644 --- a/src/generator/config/subexport.cpp +++ b/src/generator/config/subexport.cpp @@ -37,6 +37,15 @@ const string_array clash_ssr_ciphers = { "rc4-md5", "aes-128-ctr", "aes-192-ctr", "aes-256-ctr", "aes-128-cfb", "aes-192-cfb", "aes-256-cfb", "chacha20-ietf", "xchacha20", "none" }; +bool isNumeric(const std::string &str) { + for (char c: str) { + if (!std::isdigit(static_cast(c))) { + return false; + } + } + return true; +} + std::string vmessLinkConstruct(const std::string &remarks, const std::string &add, const std::string &port, const std::string &type, @@ -930,6 +939,7 @@ std::string proxyToSurge(std::vector &nodes, const std::string &base_conf std::string proxy, section, real_section; string_array args, headers; + std::string search = " Mbps"; switch (x.Type) { case ProxyType::Shadowsocks: @@ -1059,8 +1069,15 @@ std::string proxyToSurge(std::vector &nodes, const std::string &base_conf if (surge_ver < 4) continue; proxy = "hysteria, " + hostname + ", " + port + ", password=" + password; - if (x.DownSpeed) - proxy += ", download-bandwidth=" + x.DownSpeed; + if (!x.DownMbps.empty()) { + if (!isNumeric(x.DownMbps)) { + size_t pos = x.DownMbps.find(search); + if (pos != std::string::npos) { + x.DownMbps.replace(pos, search.length(), ""); + } + } + proxy += ", download-bandwidth=" +x.DownMbps; + } if (!scv.is_undef()) proxy += ",skip-cert-verify=" + std::string(scv.get() ? "true" : "false"); @@ -2517,15 +2534,6 @@ vectorToJsonArray(const std::vector &array, rapidjson::MemoryPoolAl return result; } -bool isNumeric(const std::string &str) { - for (char c: str) { - if (!std::isdigit(static_cast(c))) { - return false; - } - } - return true; -} - void proxyToSingBox(std::vector &nodes, rapidjson::Document &json, std::vector &ruleset_content_array,