mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* fix(engine): downloads refuse hosts that resolve to private addresses * fix(core): shorten the env proxy doc comment * test(producer): remote-media tests stub the download fetch seam
23 lines
921 B
TypeScript
23 lines
921 B
TypeScript
import { promises as dns } from "node:dns";
|
|
import { fetchGoesThroughEnvProxy } from "@hyperframes/core/env-proxy";
|
|
|
|
const PROBE_TIMEOUT_MS = 1000;
|
|
|
|
/**
|
|
* Whether DNS answers for `host` via c-ares, one short try per nameserver. The system lookup
|
|
* `fetch` makes cannot be aborted and holds even `process.exit`, so background requests ask this first.
|
|
*/
|
|
export async function hostAnswers(host: string): Promise<boolean> {
|
|
if (fetchGoesThroughEnvProxy()) return true;
|
|
try {
|
|
const resolver = new dns.Resolver({ timeout: PROBE_TIMEOUT_MS, tries: 1 });
|
|
const results = await Promise.allSettled([resolver.resolve4(host), resolver.resolve6(host)]);
|
|
const anyFamilyTimedOut = results.some(
|
|
(r) => r.status === "rejected" && (r.reason as NodeJS.ErrnoException).code === "ETIMEOUT",
|
|
);
|
|
return !anyFamilyTimedOut && results.some((r) => r.status === "fulfilled");
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|