Perf: use fast-uri in speedtest hosts
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

This commit is contained in:
SukkaW 2025-07-01 00:58:27 +08:00
parent 58aed6aa60
commit 3d56bb540a
3 changed files with 13 additions and 2 deletions

View File

@ -9,6 +9,8 @@ import { DomainsetOutput } from './lib/rules/domainset';
import { OUTPUT_SURGE_DIR, SOURCE_DIR } from './constants/dir';
import { $$fetch } from './lib/fetch-retry';
import { fastUri } from 'fast-uri';
interface SpeedTestServer {
url: string,
lat: string,
@ -27,7 +29,7 @@ interface SpeedTestServer {
const getSpeedtestHostsGroupsPromise = $$fetch('https://speedtest-net-servers.cdn.skk.moe/servers.json')
.then(res => res.json() as Promise<SpeedTestServer[]>)
.then((data) => data.reduce<string[]>((prev, cur) => {
let hn: string | null = null;
let hn: string | null | undefined = null;
if (cur.host) {
hn = tldts.getHostname(cur.host, { detectIp: false, validateHostname: true });
if (hn) {
@ -35,7 +37,7 @@ const getSpeedtestHostsGroupsPromise = $$fetch('https://speedtest-net-servers.cd
}
}
if (cur.url) {
hn = tldts.getHostname(cur.url, { detectIp: false, validateHostname: true });
hn = fastUri.parse(cur.url).host;
if (hn) {
prev.push(hn);
}

View File

@ -31,6 +31,7 @@
"dns2": "^2.1.0",
"fast-cidr-tools": "^0.3.2",
"fast-fifo": "^1.3.2",
"fast-uri": "^3.0.6",
"fdir": "^6.4.6",
"foxts": "^3.6.0",
"hash-wasm": "^4.12.0",

8
pnpm-lock.yaml generated
View File

@ -49,6 +49,9 @@ importers:
fast-fifo:
specifier: ^1.3.2
version: 1.3.2
fast-uri:
specifier: ^3.0.6
version: 3.0.6
fdir:
specifier: ^6.4.6
version: 6.4.6(picomatch@4.0.2)
@ -1309,6 +1312,9 @@ packages:
fast-levenshtein@2.0.6:
resolution: {integrity: sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==}
fast-uri@3.0.6:
resolution: {integrity: sha512-Atfo14OibSv5wAp4VWNsFYE1AchQRTv9cBGWET4pZWHzYshFSS9NQI6I57rdKn9croWVMbYFbLhJ+yJvmZIIHw==}
fastq@1.19.1:
resolution: {integrity: sha512-GwLTyxkCXjXbxqIhTsMI2Nui8huMPtnxg7krajPJAjnEG/iiOS7i+zCtWGZR9G0NBKbXKh6X9m9UIsYX/N6vvQ==}
@ -3199,6 +3205,8 @@ snapshots:
fast-levenshtein@2.0.6: {}
fast-uri@3.0.6: {}
fastq@1.19.1:
dependencies:
reusify: 1.1.0