mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-05 03:02:06 +00:00
Add support for exporting node list in sing-box format
This commit is contained in:
1 file changed
+33
-10
@@ -2110,12 +2110,15 @@ void proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json, std::v
|
|||||||
std::vector<Proxy> nodelist;
|
std::vector<Proxy> nodelist;
|
||||||
string_array remarks_list;
|
string_array remarks_list;
|
||||||
|
|
||||||
auto direct = buildObject(allocator, "type", "direct", "tag", "DIRECT");
|
if (!ext.nodelist)
|
||||||
outbounds.PushBack(direct, allocator);
|
{
|
||||||
auto reject = buildObject(allocator, "type", "block", "tag", "REJECT");
|
auto direct = buildObject(allocator, "type", "direct", "tag", "DIRECT");
|
||||||
outbounds.PushBack(reject, allocator);
|
outbounds.PushBack(direct, allocator);
|
||||||
auto dns = buildObject(allocator, "type", "dns", "tag", "dns-out");
|
auto reject = buildObject(allocator, "type", "block", "tag", "REJECT");
|
||||||
outbounds.PushBack(dns, allocator);
|
outbounds.PushBack(reject, allocator);
|
||||||
|
auto dns = buildObject(allocator, "type", "dns", "tag", "dns-out");
|
||||||
|
outbounds.PushBack(dns, allocator);
|
||||||
|
}
|
||||||
|
|
||||||
for (Proxy &x : nodes)
|
for (Proxy &x : nodes)
|
||||||
{
|
{
|
||||||
@@ -2256,6 +2259,13 @@ void proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json, std::v
|
|||||||
remarks_list.emplace_back(x.Remark);
|
remarks_list.emplace_back(x.Remark);
|
||||||
outbounds.PushBack(proxy, allocator);
|
outbounds.PushBack(proxy, allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ext.nodelist)
|
||||||
|
{
|
||||||
|
json | AddMemberOrReplace("outbounds", outbounds, allocator);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (const ProxyGroupConfig &x: extra_proxy_group)
|
for (const ProxyGroupConfig &x: extra_proxy_group)
|
||||||
{
|
{
|
||||||
string_array filtered_nodelist;
|
string_array filtered_nodelist;
|
||||||
@@ -2326,14 +2336,27 @@ std::string proxyToSingBox(std::vector<Proxy> &nodes, const std::string &base_co
|
|||||||
{
|
{
|
||||||
using namespace rapidjson_ext;
|
using namespace rapidjson_ext;
|
||||||
rapidjson::Document json;
|
rapidjson::Document json;
|
||||||
json.Parse(base_conf.data());
|
|
||||||
if(json.HasParseError())
|
if (!ext.nodelist)
|
||||||
{
|
{
|
||||||
writeLog(0, "sing-box base loader failed with error: " + std::string(rapidjson::GetParseError_En(json.GetParseError())), LOG_LEVEL_ERROR);
|
json.Parse(base_conf.data());
|
||||||
return "";
|
if (json.HasParseError())
|
||||||
|
{
|
||||||
|
writeLog(0, "sing-box base loader failed with error: " +
|
||||||
|
std::string(rapidjson::GetParseError_En(json.GetParseError())), LOG_LEVEL_ERROR);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
json.SetObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyToSingBox(nodes, json, ruleset_content_array, extra_proxy_group, ext);
|
proxyToSingBox(nodes, json, ruleset_content_array, extra_proxy_group, ext);
|
||||||
|
|
||||||
|
if(ext.nodelist || !ext.enable_rule_generator)
|
||||||
|
return json | SerializeObject();
|
||||||
|
|
||||||
rulesetToSingBox(json, ruleset_content_array, ext.overwrite_original_rules);
|
rulesetToSingBox(json, ruleset_content_array, ext.overwrite_original_rules);
|
||||||
|
|
||||||
return json | SerializeObject();
|
return json | SerializeObject();
|
||||||
|
|||||||
Reference in new issue
Block a user