fix: DoH 结果过滤

This commit is contained in:
xream 2024-08-29 12:30:49 +08:00
parent 9abeb4ce7b
commit f0acf4a2a7
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
2 changed files with 8 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "sub-store", "name": "sub-store",
"version": "2.14.364", "version": "2.14.365",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js", "main": "src/main.js",
"scripts": { "scripts": {

View File

@ -392,18 +392,23 @@ const DOMAIN_RESOLVERS = {
const id = hex_md5(`CUSTOM:${url}:${domain}:${type}`); const id = hex_md5(`CUSTOM:${url}:${domain}:${type}`);
const cached = resourceCache.get(id); const cached = resourceCache.get(id);
if (!noCache && cached) return cached; if (!noCache && cached) return cached;
const answerType = type === 'IPv6' ? 'AAAA' : 'A';
const res = await doh({ const res = await doh({
url, url,
domain, domain,
type: type === 'IPv6' ? 'AAAA' : 'A', type: answerType,
timeout, timeout,
edns, edns,
}); });
const { answers } = res; const { answers } = res;
if (!Array.isArray(answers) || answers.length === 0) { if (!Array.isArray(answers) || answers.length === 0) {
throw new Error('No answers'); throw new Error('No answers');
} }
const result = answers.map((i) => i?.data).filter((i) => i); const result = answers
.filter((i) => i?.type === answerType)
.map((i) => i?.data)
.filter((i) => i);
if (result.length === 0) { if (result.length === 0) {
throw new Error('No answers'); throw new Error('No answers');
} }