mirror of
https://github.com/SukkaW/Surge.git
synced 2026-09-12 18:44:36 +08:00
Wire up Dead Domain CI Check for Node.js 26 [skip ci]
This commit is contained in:
@@ -174,6 +174,8 @@ const agent = new Agent({
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export { agent as fetchAgent };
|
||||||
|
|
||||||
export interface FetchResponseProgress {
|
export interface FetchResponseProgress {
|
||||||
onResponseStart?: (contentEncoding: string | null) => void,
|
onResponseStart?: (contentEncoding: string | null) => void,
|
||||||
onEncodedBodyChunk?: (bytes: number) => void,
|
onEncodedBodyChunk?: (bytes: number) => void,
|
||||||
|
|||||||
20
Build/lib/is-domain-alive.test.ts
Normal file
20
Build/lib/is-domain-alive.test.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { describe, it } from 'mocha';
|
||||||
|
import { expect } from 'earl';
|
||||||
|
import { DOMAIN_ALIVE_REASON_MESSAGES, DOMAIN_ALIVE_REASONS } from 'domain-alive';
|
||||||
|
import { createDomainAliveMethods } from './is-domain-alive';
|
||||||
|
|
||||||
|
describe('domain-alive integration', () => {
|
||||||
|
it('constructs the checkers with the custom DoH agent', async () => {
|
||||||
|
const { isDomainAlive, isRegisterableDomainAlive } = createDomainAliveMethods({});
|
||||||
|
const [domainResult, registerableDomainResult] = await Promise.all([
|
||||||
|
isDomainAlive(''),
|
||||||
|
isRegisterableDomainAlive('')
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(domainResult.reason).toEqual(DOMAIN_ALIVE_REASONS.INVALID_DOMAIN);
|
||||||
|
expect(registerableDomainResult.reason).toEqual(DOMAIN_ALIVE_REASONS.INVALID_DOMAIN);
|
||||||
|
expect(DOMAIN_ALIVE_REASON_MESSAGES[domainResult.reason]).toEqual(
|
||||||
|
'No registerable domain could be extracted.'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createDomainAliveChecker, createRegisterableDomainAliveChecker } from 'domain-alive';
|
import { createDomainAliveChecker, createRegisterableDomainAliveChecker } from 'domain-alive';
|
||||||
import { $$fetch, fetchForDoH } from './fetch-retry';
|
import { $$fetch, fetchAgent, fetchForDoH } from './fetch-retry';
|
||||||
|
|
||||||
const dnsServers = [
|
const dnsServers = [
|
||||||
'https://8.8.8.8/dns-query', 'https://8.8.4.4/dns-query',
|
'https://8.8.8.8/dns-query', 'https://8.8.4.4/dns-query',
|
||||||
@@ -55,14 +55,13 @@ const dnsServers = [
|
|||||||
const resultCache = new Map();
|
const resultCache = new Map();
|
||||||
const registerableDomainResultCache = new Map();
|
const registerableDomainResultCache = new Map();
|
||||||
|
|
||||||
export async function getMethods() {
|
export function createDomainAliveMethods(customWhoisServersMapping: Record<string, string>) {
|
||||||
const customWhoisServersMapping = await (await ($$fetch('https://cdn.jsdelivr.net/npm/whois-servers-list@latest/list.json'))).json() as any;
|
|
||||||
|
|
||||||
const isRegisterableDomainAlive = createRegisterableDomainAliveChecker({
|
const isRegisterableDomainAlive = createRegisterableDomainAliveChecker({
|
||||||
dns: {
|
dns: {
|
||||||
dnsServers,
|
dnsServers,
|
||||||
maxAttempts: 6,
|
maxAttempts: 6,
|
||||||
customFetchForDoH: fetchForDoH as typeof fetch
|
customFetchForDoH: fetchForDoH as typeof fetch,
|
||||||
|
customAgentForDoH: fetchAgent
|
||||||
},
|
},
|
||||||
registerableDomainResultCache,
|
registerableDomainResultCache,
|
||||||
whois: {
|
whois: {
|
||||||
@@ -74,7 +73,8 @@ export async function getMethods() {
|
|||||||
dns: {
|
dns: {
|
||||||
dnsServers,
|
dnsServers,
|
||||||
maxAttempts: 6,
|
maxAttempts: 6,
|
||||||
customFetchForDoH: fetchForDoH as typeof fetch
|
customFetchForDoH: fetchForDoH as typeof fetch,
|
||||||
|
customAgentForDoH: fetchAgent
|
||||||
},
|
},
|
||||||
registerableDomainResultCache,
|
registerableDomainResultCache,
|
||||||
resultCache,
|
resultCache,
|
||||||
@@ -84,4 +84,10 @@ export async function getMethods() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return { isRegisterableDomainAlive, isDomainAlive };
|
return { isRegisterableDomainAlive, isDomainAlive };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getMethods() {
|
||||||
|
const customWhoisServersMapping = await (await ($$fetch('https://cdn.jsdelivr.net/npm/whois-servers-list@latest/list.json'))).json() as Record<string, string>;
|
||||||
|
|
||||||
|
return createDomainAliveMethods(customWhoisServersMapping);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
"build-profile": "pnpm run dexnode -r @swc-node/register ./Build/index.ts",
|
"build-profile": "pnpm run dexnode -r @swc-node/register ./Build/index.ts",
|
||||||
"bench-download": "pnpm run node ./Build/benchmark-download-client.ts",
|
"bench-download": "pnpm run node ./Build/benchmark-download-client.ts",
|
||||||
"lint": "eslint --format=sukka .",
|
"lint": "eslint --format=sukka .",
|
||||||
"test": "SWC_NODE_IGNORE_DYNAMIC=true SWC_NODE_PROJECT=tsconfig.test.json mocha --require @swc-node/register --watch-extensions ts,tsx"
|
"test": "SWC_NODE_IGNORE_DYNAMIC=true SWC_NODE_PROJECT=tsconfig.test.json mocha --require @swc-node/register --watch-extensions ts,tsx \"Build/**/*.test.ts\""
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
"ci-info": "^4.4.0",
|
"ci-info": "^4.4.0",
|
||||||
"cli-progress": "^3.12.0",
|
"cli-progress": "^3.12.0",
|
||||||
"csv-parse": "^7.0.2",
|
"csv-parse": "^7.0.2",
|
||||||
"domain-alive": "^0.1.24",
|
"domain-alive": "^0.1.25",
|
||||||
"fast-cidr-tools": "^0.3.4",
|
"fast-cidr-tools": "^0.3.4",
|
||||||
"fast-escape-regexp": "^1.0.1",
|
"fast-escape-regexp": "^1.0.1",
|
||||||
"fast-uri": "^4.1.2",
|
"fast-uri": "^4.1.2",
|
||||||
|
|||||||
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@@ -33,8 +33,8 @@ importers:
|
|||||||
specifier: ^7.0.2
|
specifier: ^7.0.2
|
||||||
version: 7.0.2
|
version: 7.0.2
|
||||||
domain-alive:
|
domain-alive:
|
||||||
specifier: ^0.1.24
|
specifier: ^0.1.25
|
||||||
version: 0.1.24(supports-color@8.1.1)
|
version: 0.1.25(supports-color@8.1.1)
|
||||||
fast-cidr-tools:
|
fast-cidr-tools:
|
||||||
specifier: ^0.3.4
|
specifier: ^0.3.4
|
||||||
version: 0.3.4
|
version: 0.3.4
|
||||||
@@ -1161,8 +1161,8 @@ packages:
|
|||||||
dom-serializer@1.4.1:
|
dom-serializer@1.4.1:
|
||||||
resolution: {integrity: sha512-VHwB3KfrcOOkelEG2ZOfxqLZdfkil8PtJi4P8N2MMXucZq2yLp75ClViUlOVwyoHEDjYU433Aq+5zWP61+RGag==}
|
resolution: {integrity: sha512-VHwB3KfrcOOkelEG2ZOfxqLZdfkil8PtJi4P8N2MMXucZq2yLp75ClViUlOVwyoHEDjYU433Aq+5zWP61+RGag==}
|
||||||
|
|
||||||
domain-alive@0.1.24:
|
domain-alive@0.1.25:
|
||||||
resolution: {integrity: sha512-/KogFcl5dnHaxKMQyWARruBtXthGaiKoIH8G61/0knCEMr59ymrYabsADbJDYjN7O0+K+0qBqdh9ewjOhLkeEw==}
|
resolution: {integrity: sha512-S3NXngSmSg2DBQHdrfzSGWe96yqIm19LJORvYqoVDXkLyG0tDoQTwbGorgbCkFkCakBdoq9KTAsjTkFNi2fMbQ==}
|
||||||
|
|
||||||
domelementtype@2.3.0:
|
domelementtype@2.3.0:
|
||||||
resolution: {integrity: sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==}
|
resolution: {integrity: sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==}
|
||||||
@@ -2957,7 +2957,7 @@ snapshots:
|
|||||||
domhandler: 4.3.1
|
domhandler: 4.3.1
|
||||||
entities: 2.2.0
|
entities: 2.2.0
|
||||||
|
|
||||||
domain-alive@0.1.24(supports-color@8.1.1):
|
domain-alive@0.1.25(supports-color@8.1.1):
|
||||||
dependencies:
|
dependencies:
|
||||||
debug: 4.4.3(supports-color@8.1.1)
|
debug: 4.4.3(supports-color@8.1.1)
|
||||||
foxts: 5.9.1
|
foxts: 5.9.1
|
||||||
|
|||||||
Reference in New Issue
Block a user