From b0c1157fe19d47aefc15edf58890aff8e0601225 Mon Sep 17 00:00:00 2001 From: xream Date: Wed, 28 Feb 2024 22:33:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E8=A7=84=E5=88=99?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/core/rule-utils/parsers.js | 2 +- backend/src/core/rule-utils/producers.js | 24 ++++++++++++++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/backend/package.json b/backend/package.json index e3daf76fd..1628701f8 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.228", + "version": "2.14.230", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/rule-utils/parsers.js b/backend/src/core/rule-utils/parsers.js index 2974a340b..ee1e4bcff 100644 --- a/backend/src/core/rule-utils/parsers.js +++ b/backend/src/core/rule-utils/parsers.js @@ -40,7 +40,7 @@ function AllRuleParser() { rule.type === 'IP-CIDR' || rule.type === 'IP-CIDR6' ) { - rule.options = params.slice(2).join(","); + rule.options = params.slice(2); } result.push(rule); } diff --git a/backend/src/core/rule-utils/producers.js b/backend/src/core/rule-utils/producers.js index 41f673c63..ea0c82bc6 100644 --- a/backend/src/core/rule-utils/producers.js +++ b/backend/src/core/rule-utils/producers.js @@ -30,8 +30,9 @@ function SurgeRuleSet() { const type = 'SINGLE'; const func = (rule) => { let output = `${rule.type},${rule.content}`; - if (rule.type === 'IP-CIDR' || rule.type === 'IP-CIDR6') { - output += rule.options ? `,${rule.options}` : ''; + if (['IP-CIDR', 'IP-CIDR6'].includes(rule.type)) { + output += + rule.options?.length > 0 ? `,${rule.options.join(',')}` : ''; } return output; }; @@ -44,6 +45,12 @@ function LoonRules() { // skip unsupported rules const UNSUPPORTED = ['DEST-PORT', 'SRC-IP', 'IN-PORT', 'PROTOCOL']; if (UNSUPPORTED.indexOf(rule.type) !== -1) return null; + if (['IP-CIDR', 'IP-CIDR6'].includes(rule.type) && rule.options) { + // Loon only supports the no-resolve option + rule.options = rule.options.filter((option) => + ['no-resolve'].includes(option), + ); + } return SurgeRuleSet().func(rule); }; return { type, func }; @@ -62,8 +69,17 @@ function ClashRuleProvider() { let output = `${TRANSFORM[rule.type] || rule.type},${ rule.content }`; - if (rule.type === 'IP-CIDR' || rule.type === 'IP-CIDR6') { - output += rule.options ? `,${rule.options}` : ''; + if (['IP-CIDR', 'IP-CIDR6'].includes(rule.type)) { + if (rule.options) { + // Clash only supports the no-resolve option + rule.options = rule.options.filter((option) => + ['no-resolve'].includes(option), + ); + } + output += + rule.options?.length > 0 + ? `,${rule.options.join(',')}` + : ''; } return output; }),