Update RouteEntity.cpp

This commit is contained in:
parhelia512 2025-10-01 18:34:46 +08:00 committed by GitHub
parent 060a735716
commit 90498afeb7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -567,14 +567,15 @@ namespace Configs {
QJsonArray RoutingChain::get_route_rules(bool forView, std::map<int, QString> outboundMap) {
QJsonArray res;
if (Configs::dataStore->adblock_enable) {
bool added_adblock;
auto createAdblockRule = []() -> QJsonObject {
QJsonObject obj;
obj["action"] = "reject";
QJsonArray jarray;
jarray.append("throne-adblocksingbox");
obj["rule_set"] = jarray;
res += obj;
}
return obj;
};
for (const auto &item: Rules) {
auto outboundTag = QString();
if (outboundMap.contains(item->outboundID)) outboundTag = outboundMap[item->outboundID];
@ -583,8 +584,14 @@ namespace Configs {
MW_show_log("Aborted generating routing section, an error has occurred");
return {};
}
if (Configs::dataStore->adblock_enable && rule_json["action"] == "route") {
res += createAdblockRule();
added_adblock = true;
}
res += rule_json;
}
if (Configs::dataStore->adblock_enable && !added_adblock)
res += createAdblockRule();
return res;
}
@ -849,4 +856,4 @@ namespace Configs {
}
JsonStore::FromJson(object);
}
}
}