From 548e11c788bcb8f26e2df2110b6d8b866c7e8d9c Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Mon, 23 Dec 2024 13:51:22 -0600 Subject: [PATCH] various fixes --- src/webpage/channel.ts | 2 +- src/webpage/direct.ts | 5 +-- src/webpage/index.ts | 1 - src/webpage/register.ts | 2 +- src/webpage/utils/utils.ts | 87 +++++++++++++++++++++----------------- 5 files changed, 53 insertions(+), 44 deletions(-) diff --git a/src/webpage/channel.ts b/src/webpage/channel.ts index 1ea91cb..442df03 100644 --- a/src/webpage/channel.ts +++ b/src/webpage/channel.ts @@ -1397,7 +1397,7 @@ class Channel extends SnowFlake { { attachments = [], replyingto = null, - }: {attachments: Blob[]; embeds: embedjson; replyingto: Message | null}, + }: {attachments: Blob[]; embeds: embedjson[]; replyingto: Message | null}, ) { let replyjson: any; if (replyingto) { diff --git a/src/webpage/direct.ts b/src/webpage/direct.ts index f803bad..922644d 100644 --- a/src/webpage/direct.ts +++ b/src/webpage/direct.ts @@ -23,7 +23,7 @@ class Direct extends Guild { this.headers = this.localuser.headers; this.channels = []; this.channelids = {}; - // @ts-ignore + // @ts-ignore it's a hack, but it's a hack that works this.properties = {}; this.roles = []; this.roleids = new Map(); @@ -337,8 +337,7 @@ dmPermissions.setPermission("CONNECT", 1); dmPermissions.setPermission("SPEAK", 1); dmPermissions.setPermission("STREAM", 1); dmPermissions.setPermission("USE_VAD", 1); - -// @ts-ignore I need to look into this lol +//@ts-ignore No clue how to fix this dumb bug lol class Group extends Channel { user: User; static contextmenu = new Contextmenu("channel menu"); diff --git a/src/webpage/index.ts b/src/webpage/index.ts index 805bfae..9542de7 100644 --- a/src/webpage/index.ts +++ b/src/webpage/index.ts @@ -182,7 +182,6 @@ import {I18n} from "./i18n.js"; } channel.sendMessage(markdown.rawString, { attachments: images, - // @ts-ignore This is valid according to the API embeds: [], // Add an empty array for the embeds property replyingto: replyingTo, }); diff --git a/src/webpage/register.ts b/src/webpage/register.ts index d379cc8..eb114ef 100644 --- a/src/webpage/register.ts +++ b/src/webpage/register.ts @@ -161,4 +161,4 @@ async function tosLogic() { tosLogic(); -(checkInstance as any).alt = tosLogic; +checkInstance.alt = tosLogic; diff --git a/src/webpage/utils/utils.ts b/src/webpage/utils/utils.ts index 2b63f19..f88bf91 100644 --- a/src/webpage/utils/utils.ts +++ b/src/webpage/utils/utils.ts @@ -224,6 +224,9 @@ const stringURLsMap = new Map< login?: string; } >(); +/** + * this fucntion checks if a string is an instance, it'll either return the API urls or false + */ export async function getapiurls(str: string): Promise< | { api: string; @@ -331,48 +334,56 @@ export async function getapiurls(str: string): Promise< return false; } } -export async function checkInstance(instance: string) { - await instancefetch; - const verify = document.getElementById("verify"); - const loginButton = (document.getElementById("loginButton") || - document.getElementById("createAccount") || - document.createElement("button")) as HTMLButtonElement; - try { - loginButton.disabled = true; - verify!.textContent = I18n.getTranslation("login.checking"); - const instanceValue = instance; - const instanceinfo = (await getapiurls(instanceValue)) as { - wellknown: string; - api: string; - cdn: string; - gateway: string; - login: string; - value: string; - }; - if (instanceinfo) { - instanceinfo.value = instanceValue; - localStorage.setItem("instanceinfo", JSON.stringify(instanceinfo)); - verify!.textContent = I18n.getTranslation("login.allGood"); - loginButton.disabled = false; - // @ts-ignore - if (checkInstance.alt) { - // @ts-ignore - checkInstance.alt(); +/** + * + * This function takes in a string and checks if the string is a valid instance + * the string may be a URL or the name of the instance + * the alt property is something you may fire on success. + */ +const checkInstance = Object.assign( + async function (instance: string) { + await instancefetch; + const verify = document.getElementById("verify"); + const loginButton = (document.getElementById("loginButton") || + document.getElementById("createAccount") || + document.createElement("button")) as HTMLButtonElement; + try { + loginButton.disabled = true; + verify!.textContent = I18n.getTranslation("login.checking"); + const instanceValue = instance; + const instanceinfo = (await getapiurls(instanceValue)) as { + wellknown: string; + api: string; + cdn: string; + gateway: string; + login: string; + value: string; + }; + if (instanceinfo) { + instanceinfo.value = instanceValue; + localStorage.setItem("instanceinfo", JSON.stringify(instanceinfo)); + verify!.textContent = I18n.getTranslation("login.allGood"); + loginButton.disabled = false; + if (checkInstance.alt) { + checkInstance.alt(); + } + setTimeout((_: any) => { + console.log(verify!.textContent); + verify!.textContent = ""; + }, 3000); + } else { + verify!.textContent = I18n.getTranslation("login.invalid"); + loginButton.disabled = true; } - setTimeout((_: any) => { - console.log(verify!.textContent); - verify!.textContent = ""; - }, 3000); - } else { + } catch { + console.log("catch"); verify!.textContent = I18n.getTranslation("login.invalid"); loginButton.disabled = true; } - } catch { - console.log("catch"); - verify!.textContent = I18n.getTranslation("login.invalid"); - loginButton.disabled = true; - } -} + }, + {} as {alt?: Function}, +); +export {checkInstance}; export function getInstances() { return instances; }