From b2a31d79934d5ba6d07f094d3cdd3068935a71c5 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Fri, 27 Sep 2024 11:27:53 -0500 Subject: [PATCH] fixes? --- src/webpage/login.ts | 11 +++++++---- src/webpage/register.ts | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/webpage/login.ts b/src/webpage/login.ts index a33ed6c..9dc4ed0 100644 --- a/src/webpage/login.ts +++ b/src/webpage/login.ts @@ -223,6 +223,9 @@ async function getapiurls(str: string): Promise< } | false >{ + function appendApi(str:string){ + return str.includes("api")?"" : (str.endsWith("/")? "api" : "/api"); + } if(!URL.canParse(str)){ const val = stringURLMap.get(str); if(stringURLMap.size===0){ @@ -240,7 +243,7 @@ async function getapiurls(str: string): Promise< const val = stringURLsMap.get(str); if(val){ const responce = await fetch( - val.api + val.api.endsWith("/") ? "" : "/" + "ping" + val.api + (val.api.endsWith("/") ? "" : "/") + "ping" ); if(responce.ok){ if(val.login){ @@ -288,17 +291,17 @@ async function getapiurls(str: string): Promise< ).then(x=>x.json()); const apiurl = new URL(info.apiEndpoint); return{ - api: info.apiEndpoint+(apiurl.pathname.includes("api") ? "" : "/api"), + api: info.apiEndpoint+appendApi(apiurl.pathname), gateway: info.gateway, cdn: info.cdn, wellknown: str, - login: info.apiEndpoint+(apiurl.pathname.includes("api") ? "" : "/api"), + login: info.apiEndpoint+appendApi(apiurl.pathname), }; }catch{ const val = stringURLsMap.get(str); if(val){ const responce = await fetch( - val.api + val.api.endsWith("/") ? "" : "/" + "ping" + val.api + (val.api.endsWith("/") ? "" : "/") + "ping" ); if(responce.ok){ if(val.login){ diff --git a/src/webpage/register.ts b/src/webpage/register.ts index 85e99f8..91fa48a 100644 --- a/src/webpage/register.ts +++ b/src/webpage/register.ts @@ -130,7 +130,8 @@ let TOSa = document.getElementById("TOSa") as HTMLAnchorElement | null; async function tosLogic(){ const instanceInfo = JSON.parse(localStorage.getItem("instanceinfo") ?? "{}"); const apiurl = new URL(instanceInfo.api); - const response = await fetch(apiurl.toString() + "/ping"); + const urlstr=apiurl.toString(); + const response = await fetch(urlstr + (urlstr.endsWith("/") ? "" : "/") + "ping"); const data = await response.json(); const tosPage = data.instance.tosPage;