mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 21:42:24 +00:00
fix subJson direct rules (#2580)
This commit is contained in:
parent
c385662783
commit
fb2b58110d
1 changed files with 44 additions and 29 deletions
|
@ -464,8 +464,7 @@
|
|||
outboundTag: "direct",
|
||||
domain: [
|
||||
"geosite:category-ir"
|
||||
],
|
||||
"enabled": true
|
||||
]
|
||||
},
|
||||
{
|
||||
type: "field",
|
||||
|
@ -473,8 +472,7 @@
|
|||
ip: [
|
||||
"geoip:private",
|
||||
"geoip:ir"
|
||||
],
|
||||
enabled: true
|
||||
]
|
||||
},
|
||||
],
|
||||
geoIPOptions: [
|
||||
|
@ -751,16 +749,25 @@
|
|||
get: function () {
|
||||
if (!this.enableDirect) return [];
|
||||
const rules = JSON.parse(this.allSetting.subJsonRules);
|
||||
return Array.isArray(rules) ? rules[1].ip.map(d => d.replace("geoip:", "")) : [];
|
||||
if (!Array.isArray(rules)) return [];
|
||||
const ipRule = rules.find(r => r.ip);
|
||||
return ipRule?.ip.map(d => d.replace("geoip:", "")) ?? [];
|
||||
},
|
||||
set: function (v) {
|
||||
const rules = JSON.parse(this.allSetting.subJsonRules);
|
||||
let rules = JSON.parse(this.allSetting.subJsonRules);
|
||||
if (!Array.isArray(rules)) return;
|
||||
|
||||
rules[1].ip = [];
|
||||
if (v.length == 0) {
|
||||
rules = rules.filter(r => !r.ip);
|
||||
} else {
|
||||
let ruleIndex = rules.findIndex(r => r.ip);
|
||||
if (ruleIndex == -1) ruleIndex = rules.push(this.defaultRules[1]) - 1;
|
||||
|
||||
rules[ruleIndex].ip = [];
|
||||
v.forEach(d => {
|
||||
rules[1].ip.push("geoip:" + d);
|
||||
rules[ruleIndex].ip.push("geoip:" + d);
|
||||
});
|
||||
}
|
||||
this.allSetting.subJsonRules = JSON.stringify(rules);
|
||||
}
|
||||
},
|
||||
|
@ -768,20 +775,27 @@
|
|||
get: function () {
|
||||
if (!this.enableDirect) return [];
|
||||
const rules = JSON.parse(this.allSetting.subJsonRules);
|
||||
return Array.isArray(rules) ?
|
||||
rules[0].domain.map(d => {
|
||||
if (!Array.isArray(rules)) return [];
|
||||
const domainRule = rules.find(r => r.domain);
|
||||
return domainRule?.domain.map(d => {
|
||||
if (d.startsWith("geosite:category-")) {
|
||||
return d.replace("geosite:category-", "");
|
||||
}
|
||||
return d.replace("geosite:", "");
|
||||
})
|
||||
: [];
|
||||
?? [];
|
||||
},
|
||||
set: function (v) {
|
||||
const rules = JSON.parse(this.allSetting.subJsonRules);
|
||||
let rules = JSON.parse(this.allSetting.subJsonRules);
|
||||
if (!Array.isArray(rules)) return;
|
||||
|
||||
rules[0].domain = [];
|
||||
if (v.length == 0) {
|
||||
rules = rules.filter(r => !r.domain);
|
||||
} else {
|
||||
let ruleIndex = rules.findIndex(r => r.domain);
|
||||
if (ruleIndex == -1) ruleIndex = rules.push(this.defaultRules[0]) - 1;
|
||||
|
||||
rules[ruleIndex].domain = [];
|
||||
v.forEach(d => {
|
||||
let category = '';
|
||||
if (["cn", "apple", "meta", "google"].includes(d)) {
|
||||
|
@ -789,8 +803,9 @@
|
|||
} else if (["ru", "ir"].includes(d)) {
|
||||
category = "category-";
|
||||
}
|
||||
rules[0].domain.push("geosite:" + category + d);
|
||||
rules[ruleIndex].domain.push("geosite:" + category + d);
|
||||
});
|
||||
}
|
||||
this.allSetting.subJsonRules = JSON.stringify(rules);
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue