Chore: re-use code

This commit is contained in:
SukkaW
2024-05-02 18:52:25 +08:00
parent 986cfc8ff4
commit fa0cb48bf0
3 changed files with 17 additions and 9 deletions

View File

@@ -6,14 +6,19 @@ const isDomainLoose = (domain: string): boolean => {
return !!(!isIp && (isIcann || isPrivate));
};
export const extractDomainsFromFelixDnsmasq = (line: string): string | null => {
if (line.startsWith('server=/') && line.endsWith('/114.114.114.114')) {
return line.slice(8, -16);
}
return null;
};
export const parseFelixDnsmasq = async (url: string | URL): Promise<string[]> => {
const res: string[] = [];
for await (const line of await fetchRemoteTextByLine(url)) {
if (line.startsWith('server=/') && line.endsWith('/114.114.114.114')) {
const domain = line.slice(8, -16);
if (isDomainLoose(domain)) {
res.push(domain);
}
const domain = extractDomainsFromFelixDnsmasq(line);
if (domain && isDomainLoose(domain)) {
res.push(domain);
}
}