mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 12:34:37 +03:00
refactor custom json
This commit is contained in:
@@ -12,6 +12,27 @@
|
||||
|
||||
namespace NekoRay {
|
||||
|
||||
void MergeJson(const QJsonObject &custom, QJsonObject &outbound) {
|
||||
// 合并
|
||||
if (custom.isEmpty()) return;
|
||||
for (const auto &key: custom.keys()) {
|
||||
if (outbound.contains(key)) {
|
||||
auto v = custom[key];
|
||||
auto v_orig = outbound[key];
|
||||
if (v.isObject() && v_orig.isObject()) { // isObject 则合并?
|
||||
auto vo = v.toObject();
|
||||
QJsonObject vo_orig = v_orig.toObject();
|
||||
MergeJson(vo, vo_orig);
|
||||
outbound[key] = vo_orig;
|
||||
} else {
|
||||
outbound[key] = v;
|
||||
}
|
||||
} else {
|
||||
outbound[key] = custom[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Common
|
||||
|
||||
QSharedPointer<BuildConfigResult> BuildConfig(const QSharedPointer<ProxyEntity> &ent, bool forTest, bool forExport) {
|
||||
@@ -33,6 +54,9 @@ namespace NekoRay {
|
||||
}
|
||||
}
|
||||
|
||||
// apply custom config
|
||||
MergeJson(QString2QJsonObject(ent->bean->custom_config), result->coreConfig);
|
||||
|
||||
// hook.js
|
||||
if (result->error.isEmpty() && !forTest) {
|
||||
auto source = qjs::ReadHookJS();
|
||||
@@ -86,27 +110,6 @@ namespace NekoRay {
|
||||
return chainTagOut;
|
||||
}
|
||||
|
||||
void ApplyCustomOutboundJsonSettings(const QJsonObject &custom, QJsonObject &outbound) {
|
||||
// 合并
|
||||
if (custom.isEmpty()) return;
|
||||
for (const auto &key: custom.keys()) {
|
||||
if (outbound.contains(key)) {
|
||||
auto v = custom[key];
|
||||
auto v_orig = outbound[key];
|
||||
if (v.isObject() && v_orig.isObject()) { // isObject 则合并?
|
||||
auto vo = v.toObject();
|
||||
QJsonObject vo_orig = v_orig.toObject();
|
||||
ApplyCustomOutboundJsonSettings(vo, vo_orig);
|
||||
outbound[key] = vo_orig;
|
||||
} else {
|
||||
outbound[key] = v;
|
||||
}
|
||||
} else {
|
||||
outbound[key] = custom[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define DOMAIN_USER_RULE \
|
||||
for (const auto &line: SplitLinesSkipSharp(dataStore->routing->proxy_domain)) { \
|
||||
if (dataStore->dns_routing) status->domainListDNSRemote += line; \
|
||||
@@ -603,10 +606,7 @@ namespace NekoRay {
|
||||
}
|
||||
|
||||
// apply custom outbound settings
|
||||
auto custom_item = ent->bean->_get("custom");
|
||||
if (custom_item != nullptr) {
|
||||
ApplyCustomOutboundJsonSettings(QString2QJsonObject(*((QString *) custom_item->ptr)), outbound);
|
||||
}
|
||||
MergeJson(QString2QJsonObject(ent->bean->custom_outbound), outbound);
|
||||
|
||||
// Bypass Lookup for the first profile
|
||||
auto serverAddress = ent->bean->serverAddress;
|
||||
|
||||
Reference in New Issue
Block a user