mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 09:10:35 +08:00
26 lines
820 B
TypeScript
26 lines
820 B
TypeScript
import { createReadlineInterfaceFromResponse } from './fetch-text-by-line';
|
|
|
|
import type { UndiciResponseData } from './fetch-retry';
|
|
import type { Response } from 'undici';
|
|
import { fastNormalizeDomain } from './normalize-domain';
|
|
|
|
export function extractDomainsFromFelixDnsmasq(line: string): string | null {
|
|
if (line.startsWith('server=/') && line.endsWith('/114.114.114.114')) {
|
|
return line.slice(8, -16);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export async function parseFelixDnsmasqFromResp(resp: UndiciResponseData | Response): Promise<string[]> {
|
|
const results: string[] = [];
|
|
|
|
for await (const line of createReadlineInterfaceFromResponse(resp, true)) {
|
|
const domain = extractDomainsFromFelixDnsmasq(line);
|
|
if (domain && fastNormalizeDomain(domain)) {
|
|
results.push(domain);
|
|
}
|
|
}
|
|
|
|
return results;
|
|
}
|