feat: let's goooo
This commit is contained in:
+3
-2
@@ -2,6 +2,7 @@ import { getTLDList } from "./tld";
|
||||
import englishWords from "@/data/english.txt?raw";
|
||||
import frenchWords from "@/data/french.txt?raw";
|
||||
import { randomElement, shuffled } from "./random";
|
||||
import type { WhoIs } from "./whois";
|
||||
|
||||
export class DomainFactory {
|
||||
tldList: string[] = [];
|
||||
@@ -9,9 +10,9 @@ export class DomainFactory {
|
||||
words: Record<string, string[]> = {};
|
||||
generated: string[] = [];
|
||||
|
||||
async init() {
|
||||
async init(whois: WhoIs) {
|
||||
try {
|
||||
this.tldList = await getTLDList();
|
||||
this.tldList = await getTLDList(whois);
|
||||
} catch (e) {
|
||||
this.error = "Could not load TLD list";
|
||||
throw e;
|
||||
|
||||
+32
-12
@@ -1,20 +1,40 @@
|
||||
export async function getTLDList(): Promise<string[]> {
|
||||
import type { WhoIs } from "./whois";
|
||||
|
||||
export async function getTLDList(whois: WhoIs): Promise<string[]> {
|
||||
const response = await fetch(
|
||||
"https://cors.klemek.fr/https://publicsuffix.org/list/public_suffix_list.dat",
|
||||
);
|
||||
const content = await response.text();
|
||||
const tldList: string[] = [];
|
||||
content.split("\n").forEach((line) => {
|
||||
line = line.trim();
|
||||
if (
|
||||
line.length &&
|
||||
!line.startsWith("//") &&
|
||||
!line.startsWith("*") &&
|
||||
line.replace(/[^\\x00-\\x7F]/g, "") === line &&
|
||||
(!line.includes(".") || tldList.every((other) => !line.endsWith(other)))
|
||||
) {
|
||||
tldList.push(line);
|
||||
// @ts-expect-error - not empty string
|
||||
content
|
||||
.split("// ===END ICANN DOMAINS===")[0]
|
||||
.split("\n")
|
||||
.forEach((line) => {
|
||||
line = line.trim();
|
||||
if (
|
||||
line.length &&
|
||||
!line.startsWith("//") &&
|
||||
!line.startsWith("*") &&
|
||||
line.replace(/[^\x20-\x7F]/g, "") === line
|
||||
) {
|
||||
tldList.forEach((other) => {
|
||||
if (line.endsWith(`.${other}`)) {
|
||||
tldList.splice(tldList.indexOf(other), 1);
|
||||
}
|
||||
});
|
||||
tldList.push(line);
|
||||
}
|
||||
});
|
||||
return tldList.filter((tld) => {
|
||||
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;
|
||||
});
|
||||
return tldList;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user