fix: better whois and smaller tld list
This commit is contained in:
+22
-9
@@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, onBeforeMount } from "vue";
|
import { ref, onMounted, onBeforeMount } from "vue";
|
||||||
import { WhoIs } from "./lib/whois";
|
import { isDomainAvailable } from "./lib/whois";
|
||||||
import { DomainFactory } from "./lib/factory";
|
import { DomainFactory } from "./lib/factory";
|
||||||
|
|
||||||
enum State {
|
enum State {
|
||||||
@@ -16,7 +16,6 @@ function getLang() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const visible = ref<boolean>(false);
|
const visible = ref<boolean>(false);
|
||||||
const whois = ref<WhoIs>(new WhoIs());
|
|
||||||
const factory = ref<DomainFactory>(new DomainFactory());
|
const factory = ref<DomainFactory>(new DomainFactory());
|
||||||
const domain = ref<string | null>(null);
|
const domain = ref<string | null>(null);
|
||||||
const domainAvailable = ref<boolean>(false);
|
const domainAvailable = ref<boolean>(false);
|
||||||
@@ -40,11 +39,10 @@ function newDomain() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkAvailability() {
|
function checkAvailability() {
|
||||||
if (!whois.value.error && domain.value) {
|
if (domain.value) {
|
||||||
const promiseDomain = domain.value;
|
const promiseDomain = domain.value;
|
||||||
state.value = State.Fetching;
|
state.value = State.Fetching;
|
||||||
whois.value
|
isDomainAvailable(promiseDomain)
|
||||||
.isDomainAvailable(promiseDomain)
|
|
||||||
.then((available) => {
|
.then((available) => {
|
||||||
if (domain.value !== promiseDomain) {
|
if (domain.value !== promiseDomain) {
|
||||||
return; // domain changed
|
return; // domain changed
|
||||||
@@ -63,9 +61,24 @@ function checkAvailability() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTextClass() {
|
||||||
|
if (!domain.value || domain.value.length < 15) {
|
||||||
|
return "text-5xl";
|
||||||
|
}
|
||||||
|
if (domain.value.length < 20) {
|
||||||
|
return "text-4xl";
|
||||||
|
}
|
||||||
|
if (domain.value.length < 25) {
|
||||||
|
return "text-3xl";
|
||||||
|
}
|
||||||
|
if (domain.value.length < 30) {
|
||||||
|
return "text-2xl";
|
||||||
|
}
|
||||||
|
return "text-xl";
|
||||||
|
}
|
||||||
|
|
||||||
onBeforeMount(async () => {
|
onBeforeMount(async () => {
|
||||||
await whois.value.init();
|
await factory.value.init();
|
||||||
await factory.value.init(whois.value);
|
|
||||||
newDomain();
|
newDomain();
|
||||||
state.value = State.Ready;
|
state.value = State.Ready;
|
||||||
});
|
});
|
||||||
@@ -86,8 +99,8 @@ onMounted(() => {
|
|||||||
<template>
|
<template>
|
||||||
<div :style="{ display: visible ? 'inherit' : 'none' }">
|
<div :style="{ display: visible ? 'inherit' : 'none' }">
|
||||||
<div class="card bg-base-100 w-xl max-w-svw shrink-0 shadow-2xl">
|
<div class="card bg-base-100 w-xl max-w-svw shrink-0 shadow-2xl">
|
||||||
<div class="card-body">
|
<div class="card-body overflow-hidden">
|
||||||
<h1 class="text-5xl font-bold font-doto">
|
<h1 class="font-bold" :class="getTextClass()">
|
||||||
<span
|
<span
|
||||||
v-if="state !== State.Loading && domain"
|
v-if="state !== State.Loading && domain"
|
||||||
class="inline-block me-2"
|
class="inline-block me-2"
|
||||||
|
|||||||
+6
-5
@@ -2,7 +2,6 @@ import { getTLDList } from "./tld";
|
|||||||
import englishWords from "@/data/english.txt?raw";
|
import englishWords from "@/data/english.txt?raw";
|
||||||
import frenchWords from "@/data/french.txt?raw";
|
import frenchWords from "@/data/french.txt?raw";
|
||||||
import { randomElement, shuffled } from "./random";
|
import { randomElement, shuffled } from "./random";
|
||||||
import type { WhoIs } from "./whois";
|
|
||||||
|
|
||||||
export class DomainFactory {
|
export class DomainFactory {
|
||||||
tldList: string[] = [];
|
tldList: string[] = [];
|
||||||
@@ -10,9 +9,9 @@ export class DomainFactory {
|
|||||||
words: Record<string, string[]> = {};
|
words: Record<string, string[]> = {};
|
||||||
generated: string[] = [];
|
generated: string[] = [];
|
||||||
|
|
||||||
async init(whois: WhoIs) {
|
async init() {
|
||||||
try {
|
try {
|
||||||
this.tldList = await getTLDList(whois);
|
this.tldList = await getTLDList();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.error = "Could not load TLD list";
|
this.error = "Could not load TLD list";
|
||||||
throw e;
|
throw e;
|
||||||
@@ -53,8 +52,10 @@ export class DomainFactory {
|
|||||||
const tldEscaped: string = tld.replace(".", "");
|
const tldEscaped: string = tld.replace(".", "");
|
||||||
if (word.endsWith(tldEscaped) && word.length > tldEscaped.length + 2) {
|
if (word.endsWith(tldEscaped) && word.length > tldEscaped.length + 2) {
|
||||||
const domain = `${word.substring(0, word.length - tldEscaped.length)}.${tld}`;
|
const domain = `${word.substring(0, word.length - tldEscaped.length)}.${tld}`;
|
||||||
this.generated.push(domain);
|
if (!domain.includes("-.")) {
|
||||||
return domain;
|
this.generated.push(domain);
|
||||||
|
return domain;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
+14
-21
@@ -1,8 +1,8 @@
|
|||||||
import type { WhoIs } from "./whois";
|
const BLACKLIST = ["able", "gle", "pin", "mil"];
|
||||||
|
|
||||||
export async function getTLDList(whois: WhoIs): Promise<string[]> {
|
export async function getTLDList(): Promise<string[]> {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
"https://cors.klemek.fr/https://publicsuffix.org/list/public_suffix_list.dat",
|
"https://cors.klemek.fr/https://data.iana.org/TLD/tlds-alpha-by-domain.txt",
|
||||||
);
|
);
|
||||||
const content = await response.text();
|
const content = await response.text();
|
||||||
const tldList: string[] = [];
|
const tldList: string[] = [];
|
||||||
@@ -11,30 +11,23 @@ export async function getTLDList(whois: WhoIs): Promise<string[]> {
|
|||||||
.split("// ===END ICANN DOMAINS===")[0]
|
.split("// ===END ICANN DOMAINS===")[0]
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.forEach((line) => {
|
.forEach((line) => {
|
||||||
line = line.trim();
|
line = line.trim().toLowerCase();
|
||||||
if (
|
if (
|
||||||
line.length &&
|
line.length &&
|
||||||
!line.startsWith("//") &&
|
!line.startsWith("//") &&
|
||||||
!line.startsWith("*") &&
|
!line.startsWith("*") &&
|
||||||
line.replace(/[^\x20-\x7F]/g, "") === line
|
!line.startsWith("#") &&
|
||||||
|
!line.startsWith("xn--") &&
|
||||||
|
line.replace(/[^\x20-\x7F]/g, "") === line &&
|
||||||
|
!BLACKLIST.includes(line)
|
||||||
) {
|
) {
|
||||||
tldList.forEach((other) => {
|
// tldList.forEach((other) => {
|
||||||
if (line.endsWith(`.${other}`)) {
|
// if (line.endsWith(`.${other}`)) {
|
||||||
tldList.splice(tldList.indexOf(other), 1);
|
// tldList.splice(tldList.indexOf(other), 1);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
tldList.push(line);
|
tldList.push(line);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return tldList.filter((tld) => {
|
return tldList;
|
||||||
if (!whois.rdapEndpoints) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
for (const rdap_tld of Object.keys(whois.rdapEndpoints)) {
|
|
||||||
if (rdap_tld == tld || tld.endsWith(`.${rdap_tld}`)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-53
@@ -1,55 +1,11 @@
|
|||||||
export class WhoIs {
|
export async function isDomainAvailable(domain: string): Promise<boolean> {
|
||||||
rdapEndpoints: Record<string, string> | null = null;
|
try {
|
||||||
error: string | null = null;
|
const response = await fetch(
|
||||||
|
`https://whois.klemek.fr/api/lookup/${domain}`,
|
||||||
async init() {
|
);
|
||||||
await this.loadRdapEndpoints();
|
const content = await response.json();
|
||||||
}
|
return content?.data?.nameservers?.length === 0;
|
||||||
|
} catch {
|
||||||
async loadRdapEndpoints() {
|
return false;
|
||||||
try {
|
|
||||||
const response = await fetch(
|
|
||||||
`https://cors.klemek.fr/https://data.iana.org/rdap/dns.json`,
|
|
||||||
);
|
|
||||||
const content: { services: { 0: string[]; 1: string[] }[] } =
|
|
||||||
await response.json();
|
|
||||||
const rdapEndpoints: Record<string, string> = {};
|
|
||||||
content.services.forEach((item) => {
|
|
||||||
if (item[1][0]) {
|
|
||||||
const supplier: string = item[1][0];
|
|
||||||
item[0].forEach((domain: string) => {
|
|
||||||
rdapEndpoints[domain] = supplier;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.rdapEndpoints = rdapEndpoints;
|
|
||||||
} catch (e) {
|
|
||||||
this.error = "Could not load RDAP endpoints";
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getRdapQuery(domain: string): string {
|
|
||||||
if (this.rdapEndpoints === null) {
|
|
||||||
throw Error("RDAP endpoints not loaded");
|
|
||||||
}
|
|
||||||
for (const tld of Object.keys(this.rdapEndpoints)) {
|
|
||||||
if (domain.endsWith(`.${tld}`) && this.rdapEndpoints[tld]) {
|
|
||||||
return `${this.rdapEndpoints[tld]}/domain/${domain}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw Error(`RDAP supplier not found for ${domain}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
async isDomainAvailable(domain: string): Promise<boolean> {
|
|
||||||
const url = this.getRdapQuery(domain);
|
|
||||||
try {
|
|
||||||
const response = await fetch(`https://cors.klemek.fr/${url}`, {
|
|
||||||
method: "HEAD",
|
|
||||||
});
|
|
||||||
return response.status === 404;
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user