fix: check more whois data
This commit is contained in:
+30
-7
@@ -1,15 +1,38 @@
|
||||
import type {
|
||||
WhoIsResponse,
|
||||
WhoIsData,
|
||||
WhoIsEvent,
|
||||
WhoIsIpAddresses,
|
||||
} from "@/types";
|
||||
|
||||
function checkEvents(events: WhoIsEvent[]): boolean {
|
||||
for (const event of events) {
|
||||
if (event.eventAction === "registration" && event.eventDate === "") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkIpAddresses(ipAddresses: WhoIsIpAddresses): boolean {
|
||||
return ipAddresses.v4.length === 0 && ipAddresses.v6.length === 0;
|
||||
}
|
||||
|
||||
function checkWhoIsData(data: WhoIsData): boolean {
|
||||
return (
|
||||
checkEvents(data.events) &&
|
||||
checkIpAddresses(data.ipAddresses) &&
|
||||
data.nameservers.length === 0
|
||||
);
|
||||
}
|
||||
|
||||
export async function isDomainAvailable(domain: string): Promise<boolean> {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://whois.klemek.fr/api/lookup/${domain}`,
|
||||
);
|
||||
const content = await response.json();
|
||||
for (const event of content?.data?.events ?? []) {
|
||||
if (event?.eventAction === "registration" && event?.eventDate === "") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
const content: WhoIsResponse = await response.json();
|
||||
return checkWhoIsData(content.data);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user