fix: fixed list of tlds
This commit is contained in:
+2
-3
@@ -77,10 +77,9 @@ function getTextClass() {
|
||||
return "text-xl";
|
||||
}
|
||||
|
||||
onBeforeMount(async () => {
|
||||
await factory.value.init();
|
||||
onBeforeMount(() => {
|
||||
factory.value.init();
|
||||
newDomain();
|
||||
state.value = State.Ready;
|
||||
});
|
||||
onMounted(() => {
|
||||
setTimeout(() => {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+2598
File diff suppressed because it is too large
Load Diff
+5
-11
@@ -1,22 +1,16 @@
|
||||
import { getTLDList } from "./tld";
|
||||
import rawTldList from "@/data/tld.txt?raw";
|
||||
import englishWords from "@/data/english.txt?raw";
|
||||
import frenchWords from "@/data/french.txt?raw";
|
||||
import { randomElement, shuffled } from "./random";
|
||||
|
||||
const TLD_LIST: string[] = rawTldList.trim().split("\n");
|
||||
|
||||
export class DomainFactory {
|
||||
tldList: string[] = [];
|
||||
error: string | null = null;
|
||||
words: Record<string, string[]> = {};
|
||||
generated: string[] = [];
|
||||
|
||||
async init() {
|
||||
try {
|
||||
this.tldList = await getTLDList();
|
||||
} catch (e) {
|
||||
this.error = "Could not load TLD list";
|
||||
throw e;
|
||||
}
|
||||
|
||||
init() {
|
||||
this.words.french = this.initWords(frenchWords);
|
||||
this.words.english = this.initWords(englishWords);
|
||||
}
|
||||
@@ -48,7 +42,7 @@ export class DomainFactory {
|
||||
|
||||
randomDomain(lang: string): string | null {
|
||||
const word = this.randomWord(lang);
|
||||
for (const tld of shuffled(this.tldList.slice())) {
|
||||
for (const tld of shuffled(TLD_LIST.slice())) {
|
||||
const tldEscaped: string = tld.replace(".", "");
|
||||
if (word.endsWith(tldEscaped) && word.length > tldEscaped.length + 2) {
|
||||
const domain = `${word.substring(0, word.length - tldEscaped.length)}.${tld}`;
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import raw_blacklist from "@/data/blacklist.txt";
|
||||
|
||||
const BLACKLIST = raw_blacklist.split("\n");
|
||||
|
||||
export async function getTLDList(): Promise<string[]> {
|
||||
const response = await fetch(
|
||||
"https://cors.klemek.fr/https://data.iana.org/TLD/tlds-alpha-by-domain.txt",
|
||||
);
|
||||
const content = await response.text();
|
||||
const tldList: string[] = [];
|
||||
content.split("\n").forEach((line) => {
|
||||
line = line.trim().toLowerCase();
|
||||
if (
|
||||
line.length &&
|
||||
!line.startsWith("//") &&
|
||||
!line.startsWith("*") &&
|
||||
!line.startsWith("#") &&
|
||||
!line.startsWith("xn--") &&
|
||||
line.replace(/[^\x20-\x7F]/g, "") === line &&
|
||||
!BLACKLIST.includes(line)
|
||||
) {
|
||||
tldList.push(line);
|
||||
}
|
||||
});
|
||||
return tldList;
|
||||
}
|
||||
Reference in New Issue
Block a user