mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2026-04-07 16:53:16 +08:00
feat: 域名解析支持自定义 DoH(需新版前端)
This commit is contained in:
@@ -1,13 +1,8 @@
|
||||
import { Buffer } from 'buffer';
|
||||
import rs from '@/utils/rs';
|
||||
import YAML from '@/utils/yaml';
|
||||
import download from '@/utils/download';
|
||||
import {
|
||||
isIPv4,
|
||||
isIPv6,
|
||||
isValidPortNumber,
|
||||
isNotBlank,
|
||||
utf8ArrayToStr,
|
||||
} from '@/utils';
|
||||
import { isIPv4, isIPv6, isValidPortNumber, isNotBlank } from '@/utils';
|
||||
import PROXY_PROCESSORS, { ApplyProcessor } from './processors';
|
||||
import PROXY_PREPROCESSORS from './preprocessors';
|
||||
import PROXY_PRODUCERS from './producers';
|
||||
@@ -427,6 +422,7 @@ function lastParse(proxy) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof proxy.name !== 'string') {
|
||||
if (/^\d+$/.test(proxy.name)) {
|
||||
proxy.name = `${proxy.name}`;
|
||||
@@ -435,7 +431,7 @@ function lastParse(proxy) {
|
||||
if (proxy.name?.data) {
|
||||
proxy.name = Buffer.from(proxy.name.data).toString('utf8');
|
||||
} else {
|
||||
proxy.name = utf8ArrayToStr(proxy.name);
|
||||
proxy.name = Buffer.from(proxy.name).toString('utf8');
|
||||
}
|
||||
} catch (e) {
|
||||
$.error(`proxy.name decode failed\nReason: ${e}`);
|
||||
|
||||
@@ -3,6 +3,7 @@ import scriptResourceCache from '@/utils/script-resource-cache';
|
||||
import { isIPv4, isIPv6 } from '@/utils';
|
||||
import { FULL } from '@/utils/logical';
|
||||
import { getFlag, removeFlag } from '@/utils/geo';
|
||||
import { doh } from '@/utils/dns';
|
||||
import lodash from 'lodash';
|
||||
import $ from '@/core/app';
|
||||
import { hex_md5 } from '@/vendor/md5';
|
||||
@@ -390,6 +391,27 @@ function parseIP4P(IP4P) {
|
||||
}
|
||||
|
||||
const DOMAIN_RESOLVERS = {
|
||||
Custom: async function (domain, type, noCache, timeout, url) {
|
||||
const id = hex_md5(`CUSTOM:${url}:${domain}:${type}`);
|
||||
const cached = resourceCache.get(id);
|
||||
if (!noCache && cached) return cached;
|
||||
const res = await doh({
|
||||
url,
|
||||
domain,
|
||||
type: type === 'IPv6' ? 'AAAA' : 'A',
|
||||
timeout,
|
||||
});
|
||||
const { answers } = res;
|
||||
if (!Array.isArray(answers) || answers.length === 0) {
|
||||
throw new Error('No answers');
|
||||
}
|
||||
const result = answers.map((i) => i?.data).filter((i) => i);
|
||||
if (result.length === 0) {
|
||||
throw new Error('No answers');
|
||||
}
|
||||
resourceCache.set(id, result);
|
||||
return result;
|
||||
},
|
||||
Google: async function (domain, type, noCache, timeout) {
|
||||
const id = hex_md5(`GOOGLE:${domain}:${type}`);
|
||||
const cached = resourceCache.get(id);
|
||||
@@ -528,6 +550,7 @@ function ResolveDomainOperator({
|
||||
type: _type,
|
||||
filter,
|
||||
cache,
|
||||
url,
|
||||
timeout,
|
||||
}) {
|
||||
if (['IPv6', 'IP4P'].includes(_type) && ['IP-API'].includes(provider)) {
|
||||
@@ -541,6 +564,7 @@ function ResolveDomainOperator({
|
||||
if (!resolver) {
|
||||
throw new Error(`找不到域名解析服务提供方: ${provider}`);
|
||||
}
|
||||
$.info(`Domain Resolver: [${_type}] ${provider} ${url || ''}`);
|
||||
return {
|
||||
name: 'Resolve Domain Operator',
|
||||
func: async (proxies) => {
|
||||
@@ -568,6 +592,7 @@ function ResolveDomainOperator({
|
||||
type,
|
||||
cache === 'disabled',
|
||||
requestTimeout,
|
||||
url,
|
||||
)
|
||||
.then((ip) => {
|
||||
results[domain] = ip;
|
||||
|
||||
Reference in New Issue
Block a user