parse-dnsmasq.ts 731 B

123456789101112131415161718192021222324
  1. import { createReadlineInterfaceFromResponse } from './fetch-text-by-line';
  2. import type { UndiciResponseData } from './fetch-retry';
  3. import type { Response } from 'undici';
  4. export function extractDomainsFromFelixDnsmasq(line: string): string | null {
  5. if (line.startsWith('server=/') && line.endsWith('/114.114.114.114')) {
  6. return line.slice(8, -16);
  7. }
  8. return null;
  9. }
  10. export async function parseFelixDnsmasqFromResp(resp: UndiciResponseData | Response): Promise<string[]> {
  11. const results: string[] = [];
  12. for await (const line of createReadlineInterfaceFromResponse(resp, true)) {
  13. const domain = extractDomainsFromFelixDnsmasq(line);
  14. if (domain) {
  15. results.push(domain);
  16. }
  17. }
  18. return results;
  19. }