mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2025-10-27 20:03:01 +00:00
Enhancements
Fix load-balance in Surge configuration not being generated correctly. Add persistent and evaluate-before-use options to Surge proxy-groups.
This commit is contained in:
@@ -32,6 +32,8 @@ namespace toml
|
||||
conf.Tolerance = toml::find_or<Integer>(v, "tolerance", 0);
|
||||
if(v.contains("lazy"))
|
||||
conf.Lazy = toml::find_or<bool>(v, "lazy", false);
|
||||
if(v.contains("evaluate-before-use"))
|
||||
conf.EvaluateBeforeUse = toml::find_or(v, "evaluate-before-use", conf.EvaluateBeforeUse.get());
|
||||
break;
|
||||
case "load-balance"_hash:
|
||||
conf.Type = ProxyGroupType::LoadBalance;
|
||||
@@ -46,11 +48,15 @@ namespace toml
|
||||
conf.Strategy = BalanceStrategy::RoundRobin;
|
||||
break;
|
||||
}
|
||||
if(v.contains("persistent"))
|
||||
conf.Persistent = toml::find_or(v, "persistent", conf.Persistent.get());
|
||||
break;
|
||||
case "fallback"_hash:
|
||||
conf.Type = ProxyGroupType::Fallback;
|
||||
conf.Url = toml::find<String>(v, "url");
|
||||
conf.Interval = toml::find<Integer>(v, "interval");
|
||||
if(v.contains("evaluate-before-use"))
|
||||
conf.EvaluateBeforeUse = toml::find_or(v, "evaluate-before-use", conf.EvaluateBeforeUse.get());
|
||||
break;
|
||||
case "relay"_hash:
|
||||
conf.Type = ProxyGroupType::Relay;
|
||||
|
||||
@@ -32,6 +32,8 @@ struct ProxyGroupConfig
|
||||
BalanceStrategy Strategy = BalanceStrategy::ConsistentHashing;
|
||||
Boolean Lazy;
|
||||
Boolean DisableUdp;
|
||||
Boolean Persistent;
|
||||
Boolean EvaluateBeforeUse;
|
||||
|
||||
String TypeStr() const
|
||||
{
|
||||
|
||||
@@ -100,11 +100,11 @@ void rulesetToClash(YAML::Node &base_rule, std::vector<RulesetContent> &ruleset_
|
||||
std::string rule_group, retrieved_rules, strLine;
|
||||
std::stringstream strStrm;
|
||||
const std::string field_name = new_field_name ? "rules" : "Rule";
|
||||
YAML::Node Rules;
|
||||
YAML::Node rules;
|
||||
size_t total_rules = 0;
|
||||
|
||||
if(!overwrite_original_rules && base_rule[field_name].IsDefined())
|
||||
Rules = base_rule[field_name];
|
||||
rules = base_rule[field_name];
|
||||
|
||||
for(RulesetContent &x : ruleset_content_array)
|
||||
{
|
||||
@@ -154,16 +154,16 @@ void rulesetToClash(YAML::Node &base_rule, std::vector<RulesetContent> &ruleset_
|
||||
if(count_least(strLine, ',', 3))
|
||||
strLine = regReplace(strLine, "^(.*?,.*?)(,.*)(,.*)$", "$1$3$2");
|
||||
allRules.emplace_back(std::move(strLine));
|
||||
//Rules.push_back(strLine);
|
||||
//rules.push_back(strLine);
|
||||
}
|
||||
}
|
||||
|
||||
for(std::string &x : allRules)
|
||||
{
|
||||
Rules.push_back(x);
|
||||
rules.push_back(x);
|
||||
}
|
||||
|
||||
base_rule[field_name] = Rules;
|
||||
base_rule[field_name] = rules;
|
||||
}
|
||||
|
||||
std::string rulesetToClashStr(YAML::Node &base_rule, std::vector<RulesetContent> &ruleset_content_array, bool overwrite_original_rules, bool new_field_name)
|
||||
|
||||
@@ -580,6 +580,8 @@ std::string proxyToClash(std::vector<Proxy> &nodes, const std::string &base_conf
|
||||
|
||||
std::string output_content = rulesetToClashStr(yamlnode, ruleset_content_array, ext.overwrite_original_rules, ext.clash_new_field_name);
|
||||
output_content.insert(0, YAML::Dump(yamlnode));
|
||||
//rulesetToClash(yamlnode, ruleset_content_array, ext.overwrite_original_rules, ext.clash_new_field_name);
|
||||
//std::string output_content = YAML::Dump(yamlnode);
|
||||
|
||||
return output_content;
|
||||
}
|
||||
@@ -790,9 +792,9 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
|
||||
case ProxyGroupType::Fallback:
|
||||
break;
|
||||
case ProxyGroupType::LoadBalance:
|
||||
if(surge_ver < 1)
|
||||
if(surge_ver < 1 && surge_ver != -3)
|
||||
continue;
|
||||
[[fallthrough]];
|
||||
break;
|
||||
case ProxyGroupType::SSID:
|
||||
proxy = x.TypeStr() + ",default=" + x.Proxies[0] + ",";
|
||||
proxy += join(x.Proxies.begin() + 1, x.Proxies.end(), ",");
|
||||
@@ -823,16 +825,18 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
|
||||
|
||||
proxy = x.TypeStr() + ",";
|
||||
proxy += join(filtered_nodelist, ",");
|
||||
if(x.Type == ProxyGroupType::URLTest || x.Type == ProxyGroupType::Fallback)
|
||||
if(x.Type == ProxyGroupType::URLTest || x.Type == ProxyGroupType::Fallback || x.Type == ProxyGroupType::LoadBalance)
|
||||
{
|
||||
proxy += ",url=" + x.Url + ",interval=" + std::to_string(x.Interval);
|
||||
if(x.Tolerance > 0)
|
||||
proxy += ",tolerance=" + std::to_string(x.Tolerance);
|
||||
if(x.Timeout > 0)
|
||||
proxy += ",timeout=" + std::to_string(x.Timeout);
|
||||
if(!x.Persistent.is_undef())
|
||||
proxy += ",persistent=" + x.Persistent.get_str();
|
||||
if(!x.EvaluateBeforeUse.is_undef())
|
||||
proxy += ",evaluate-before-use=" + x.EvaluateBeforeUse.get_str();
|
||||
}
|
||||
else if(x.Type == ProxyGroupType::LoadBalance)
|
||||
proxy += ",url=" + x.Url;
|
||||
|
||||
ini.Set("{NONAME}", x.Name + " = " + proxy); //insert order
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user