Feat: make DoH supports multiple IP (w/ Hosts)

This commit is contained in:
SukkaW
2024-05-08 02:00:50 +08:00
parent 804e14facb
commit c8645a2713
2 changed files with 31 additions and 13 deletions

View File

@@ -27,11 +27,7 @@ export const buildDomesticRuleset = task(import.meta.path, async (span) => {
'This file contains known addresses that are avaliable in the Mainland China.'
];
const promise = getDomesticDomainsRulesetPromise();
const peeked = Bun.peek(promise);
const res: string[] = peeked === promise
? await promise
: (peeked as string[]);
const res = await getDomesticDomainsRulesetPromise();
return Promise.all([
createRuleset(
@@ -53,11 +49,17 @@ export const buildDomesticRuleset = task(import.meta.path, async (span) => {
'[Host]',
...Object.entries(DOMESTICS)
.flatMap(
([, { domains, dns }]) => domains.flatMap((domain) => [
([, { domains, dns, ...rest }]) => [
...(
'hosts' in rest
? Object.entries(rest.hosts).flatMap(([dns, ips]: [dns: string, ips: string[]]) => `${dns} = ${ips.join(', ')}`)
: []
),
...domains.flatMap((domain) => [
`${domain} = server:${dns}`,
`*.${domain} = server:${dns}`
])
)
])
],
path.resolve(import.meta.dir, '../Modules/sukka_local_dns_mapping.sgmodule')
)