Chore: refactor fetch text by line & load previous speedtest set

This commit is contained in:
SukkaW
2023-12-31 00:04:17 +08:00
parent a4458ee367
commit 48b3c4538e
2 changed files with 25 additions and 27 deletions

View File

@@ -10,6 +10,8 @@ import { fetchWithRetry } from './lib/fetch-retry';
import { SHARED_DESCRIPTION } from './lib/constants';
import { getGorhillPublicSuffixPromise } from './lib/get-gorhill-publicsuffix';
import picocolors from 'picocolors';
import { fetchRemoteTextByLine } from './lib/fetch-text-by-line';
import { processLine } from './lib/process-line';
const s = new Sema(2);
@@ -65,6 +67,7 @@ const querySpeedtestApi = async (keyword: string): Promise<Array<string | null>>
};
export const buildSpeedtestDomainSet = task(import.meta.path, async () => {
// Predefined domainset
/** @type {Set<string>} */
const domains = new Set<string>([
'.speedtest.net',
@@ -130,6 +133,14 @@ export const buildSpeedtestDomainSet = task(import.meta.path, async () => {
'.backend.librespeed.org'
]);
// Download previous speedtest domainset
for await (const l of await fetchRemoteTextByLine('https://ruleset.skk.moe/List/domainset/speedtest.conf')) {
const line = processLine(l);
if (line) {
domains.add(line);
}
}
let timer;
const pMap = ([