mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Feat: introduce make-fetch-happen (#44)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { createReadlineInterfaceFromResponse } from './fetch-text-by-line';
|
||||
import { parse as tldtsParse } from 'tldts';
|
||||
import { fetchWithRetry, defaultRequestInit } from './fetch-retry';
|
||||
import { $fetch } from './make-fetch-happen';
|
||||
import type { NodeFetchResponse } from './make-fetch-happen';
|
||||
|
||||
const isDomainLoose = (domain: string): boolean => {
|
||||
const { isIcann, isPrivate, isIp } = tldtsParse(domain);
|
||||
@@ -14,7 +15,7 @@ export const extractDomainsFromFelixDnsmasq = (line: string): string | null => {
|
||||
return null;
|
||||
};
|
||||
|
||||
export const parseFelixDnsmasqFromResp = async (resp: Response): Promise<string[]> => {
|
||||
export const parseFelixDnsmasqFromResp = async (resp: Response | NodeFetchResponse): Promise<string[]> => {
|
||||
const results: string[] = [];
|
||||
|
||||
for await (const line of createReadlineInterfaceFromResponse(resp)) {
|
||||
@@ -27,7 +28,7 @@ export const parseFelixDnsmasqFromResp = async (resp: Response): Promise<string[
|
||||
return results;
|
||||
};
|
||||
|
||||
export const parseFelixDnsmasq = async (url: string | URL): Promise<string[]> => {
|
||||
const resp = await fetchWithRetry(url, defaultRequestInit);
|
||||
export const parseFelixDnsmasq = async (url: string): Promise<string[]> => {
|
||||
const resp = await $fetch(url);
|
||||
return parseFelixDnsmasqFromResp(resp);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user