From c7d00ac5129b9d4bdde5c2917f2adc0a6488e3aa Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 19 Jan 2024 21:43:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9F=9F=E5=90=8D=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=B1=BB=E5=9E=8B=E5=92=8C=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- .../src/core/proxy-utils/processors/index.js | 51 ++++++++++++------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/backend/package.json b/backend/package.json index 920f9cb..8cb3c04 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.184", + "version": "2.14.185", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/processors/index.js b/backend/src/core/proxy-utils/processors/index.js index 75b5259..d8fc897 100644 --- a/backend/src/core/proxy-utils/processors/index.js +++ b/backend/src/core/proxy-utils/processors/index.js @@ -348,14 +348,14 @@ function ScriptOperator(script, targetPlatform, $arguments, source) { } const DOMAIN_RESOLVERS = { - Google: async function (domain) { - const id = hex_md5(`GOOGLE:${domain}`); + Google: async function (domain, type) { + const id = hex_md5(`GOOGLE:${domain}:${type}`); const cached = resourceCache.get(id); if (cached) return cached; const resp = await $.http.get({ url: `https://8.8.4.4/resolve?name=${encodeURIComponent( domain, - )}&type=A`, + )}&type=${type === 'IPv6' ? 'AAAA' : 'A'}`, headers: { accept: 'application/dns-json', }, @@ -389,14 +389,14 @@ const DOMAIN_RESOLVERS = { resourceCache.set(id, result); return result; }, - Cloudflare: async function (domain) { - const id = hex_md5(`CLOUDFLARE:${domain}`); + Cloudflare: async function (domain, type) { + const id = hex_md5(`CLOUDFLARE:${domain}:${type}`); const cached = resourceCache.get(id); if (cached) return cached; const resp = await $.http.get({ url: `https://1.0.0.1/dns-query?name=${encodeURIComponent( domain, - )}&type=A`, + )}&type=${type === 'IPv6' ? 'AAAA' : 'A'}`, headers: { accept: 'application/dns-json', }, @@ -413,14 +413,14 @@ const DOMAIN_RESOLVERS = { resourceCache.set(id, result); return result; }, - Ali: async function (domain) { - const id = hex_md5(`ALI:${domain}`); + Ali: async function (domain, type) { + const id = hex_md5(`ALI:${domain}:${type}`); const cached = resourceCache.get(id); if (cached) return cached; const resp = await $.http.get({ url: `http://223.6.6.6/resolve?name=${encodeURIComponent( domain, - )}&type=A&short=1`, + )}&type=${type === 'IPv6' ? 'AAAA' : 'A'}&short=1`, headers: { accept: 'application/dns-json', }, @@ -433,14 +433,14 @@ const DOMAIN_RESOLVERS = { resourceCache.set(id, result); return result; }, - Tencent: async function (domain) { - const id = hex_md5(`ALI:${domain}`); + Tencent: async function (domain, type) { + const id = hex_md5(`ALI:${domain}:${type}`); const cached = resourceCache.get(id); if (cached) return cached; const resp = await $.http.get({ - url: `http://119.28.28.28/d?type=A&dn=${encodeURIComponent( - domain, - )}`, + url: `http://119.28.28.28/d?type=${ + type === 'IPv6' ? 'AAAA' : 'A' + }&dn=${encodeURIComponent(domain)}`, headers: { accept: 'application/dns-json', }, @@ -455,10 +455,13 @@ const DOMAIN_RESOLVERS = { }, }; -function ResolveDomainOperator({ provider }) { +function ResolveDomainOperator({ provider, type, filter }) { + if (type === 'IPv6' && ['IP-API'].includes(provider)) { + throw new Error(`域名解析服务提供方 ${provider} 不支持 IPv6`); + } const resolver = DOMAIN_RESOLVERS[provider]; if (!resolver) { - throw new Error(`Cannot find resolver: ${provider}`); + throw new Error(`找不到域名解析服务提供方: ${provider}`); } return { name: 'Resolve Domain Operator', @@ -477,7 +480,7 @@ function ResolveDomainOperator({ provider }) { const currentBatch = []; for (let domain of totalDomain.splice(0, limit)) { currentBatch.push( - resolver(domain) + resolver(domain, type) .then((ip) => { results[domain] = ip; $.info( @@ -504,7 +507,19 @@ function ResolveDomainOperator({ provider }) { } }); - return proxies; + return proxies.filter((p) => { + if (filter === 'removeFailed') { + return p['no-resolve'] || p.resolved; + } else if (filter === 'IPOnly') { + return isIP(p.server); + } else if (filter === 'IPv4Only') { + return isIPv4(p.server); + } else if (filter === 'IPv6Only') { + return isIPv6(p.server); + } else { + return true; + } + }); }, }; }