This commit is contained in:
MathMan05 2024-09-27 11:27:53 -05:00
parent e49090d4bf
commit b2a31d7993
2 changed files with 9 additions and 5 deletions

View file

@ -223,6 +223,9 @@ async function getapiurls(str: string): Promise<
} }
| false | false
>{ >{
function appendApi(str:string){
return str.includes("api")?"" : (str.endsWith("/")? "api" : "/api");
}
if(!URL.canParse(str)){ if(!URL.canParse(str)){
const val = stringURLMap.get(str); const val = stringURLMap.get(str);
if(stringURLMap.size===0){ if(stringURLMap.size===0){
@ -240,7 +243,7 @@ async function getapiurls(str: string): Promise<
const val = stringURLsMap.get(str); const val = stringURLsMap.get(str);
if(val){ if(val){
const responce = await fetch( const responce = await fetch(
val.api + val.api.endsWith("/") ? "" : "/" + "ping" val.api + (val.api.endsWith("/") ? "" : "/") + "ping"
); );
if(responce.ok){ if(responce.ok){
if(val.login){ if(val.login){
@ -288,17 +291,17 @@ async function getapiurls(str: string): Promise<
).then(x=>x.json()); ).then(x=>x.json());
const apiurl = new URL(info.apiEndpoint); const apiurl = new URL(info.apiEndpoint);
return{ return{
api: info.apiEndpoint+(apiurl.pathname.includes("api") ? "" : "/api"), api: info.apiEndpoint+appendApi(apiurl.pathname),
gateway: info.gateway, gateway: info.gateway,
cdn: info.cdn, cdn: info.cdn,
wellknown: str, wellknown: str,
login: info.apiEndpoint+(apiurl.pathname.includes("api") ? "" : "/api"), login: info.apiEndpoint+appendApi(apiurl.pathname),
}; };
}catch{ }catch{
const val = stringURLsMap.get(str); const val = stringURLsMap.get(str);
if(val){ if(val){
const responce = await fetch( const responce = await fetch(
val.api + val.api.endsWith("/") ? "" : "/" + "ping" val.api + (val.api.endsWith("/") ? "" : "/") + "ping"
); );
if(responce.ok){ if(responce.ok){
if(val.login){ if(val.login){

View file

@ -130,7 +130,8 @@ let TOSa = document.getElementById("TOSa") as HTMLAnchorElement | null;
async function tosLogic(){ async function tosLogic(){
const instanceInfo = JSON.parse(localStorage.getItem("instanceinfo") ?? "{}"); const instanceInfo = JSON.parse(localStorage.getItem("instanceinfo") ?? "{}");
const apiurl = new URL(instanceInfo.api); 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 data = await response.json();
const tosPage = data.instance.tosPage; const tosPage = data.instance.tosPage;