Surge_by_SukkaW/Build/lib/parse-dnsmasq.ts
SukkaW f6abcc2e01
Some checks failed
Build / Build (push) Has been cancelled
Build / Diff output (push) Has been cancelled
Build / Deploy to Cloudflare Pages (3.114.9) (push) Has been cancelled
Build / Deploy to GitHub and GitLab (push) Has been cancelled
Chore: minor changes
2025-06-18 22:28:20 +08:00

25 lines
731 B
TypeScript

import { createReadlineInterfaceFromResponse } from './fetch-text-by-line';
import type { UndiciResponseData } from './fetch-retry';
import type { Response } from 'undici';
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) {
results.push(domain);
}
}
return results;
}