update login logic

This commit is contained in:
MathMan05 2024-09-24 12:02:20 -05:00
parent b5e5c436f8
commit 9ae7a9c71f
2 changed files with 76 additions and 59 deletions

View file

@ -3,6 +3,12 @@
"name": "Spacebar", "name": "Spacebar",
"description": "The official Spacebar instance.", "description": "The official Spacebar instance.",
"image": "https://raw.githubusercontent.com/spacebarchat/spacebarchat/master/branding/png/Spacebar__Icon-Discord.png", "image": "https://raw.githubusercontent.com/spacebarchat/spacebarchat/master/branding/png/Spacebar__Icon-Discord.png",
"urls":{
"wellknown": "https://spacebar.chat/",
"api": "https://old.server.spacebar.chat/api",
"cdn": "https://cdn.old.server.spacebar.chat",
"gateway": "wss://gateway.old.server.spacebar.chat"
},
"url": "https://spacebar.chat" "url": "https://spacebar.chat"
}, },
{ {

View file

@ -214,7 +214,7 @@ const stringURLsMap = new Map<
} }
>(); >();
async function getapiurls(str: string): Promise< async function getapiurls(str: string): Promise<
| { {
api: string; api: string;
cdn: string; cdn: string;
gateway: string; gateway: string;
@ -225,6 +225,15 @@ async function getapiurls(str: string): Promise<
>{ >{
if(!URL.canParse(str)){ if(!URL.canParse(str)){
const val = stringURLMap.get(str); const val = stringURLMap.get(str);
if(stringURLMap.size===0){
await new Promise<void>(res=>{
setInterval(()=>{
if(stringURLMap.size!==0){
res();
}
},100)
})
}
if(val){ if(val){
str = val; str = val;
}else{ }else{
@ -236,21 +245,21 @@ async function getapiurls(str: string): Promise<
if(responce.ok){ if(responce.ok){
if(val.login){ if(val.login){
return val as { return val as {
wellknown: string; wellknown: string;
api: string; api: string;
cdn: string; cdn: string;
gateway: string; gateway: string;
login: string; login: string;
}; };
}else{ }else{
val.login = val.api; val.login = val.api;
return val as { return val as {
wellknown: string; wellknown: string;
api: string; api: string;
cdn: string; cdn: string;
gateway: string; gateway: string;
login: string; login: string;
}; };
} }
} }
} }
@ -265,6 +274,9 @@ async function getapiurls(str: string): Promise<
); );
api = info.api; api = info.api;
}catch{ }catch{
api=str;
}
if(!URL.canParse(api)){
return false; return false;
} }
const url = new URL(api); const url = new URL(api);
@ -314,35 +326,35 @@ async function getapiurls(str: string): Promise<
async function checkInstance(instance?: string){ async function checkInstance(instance?: string){
const verify = document.getElementById("verify"); const verify = document.getElementById("verify");
try{ try{
verify!.textContent = "Checking Instance"; verify!.textContent = "Checking Instance";
const instanceValue = instance || (instancein as HTMLInputElement).value; const instanceValue = instance || (instancein as HTMLInputElement).value;
const instanceinfo = (await getapiurls(instanceValue)) as { const instanceinfo = (await getapiurls(instanceValue)) as {
wellknown: string; wellknown: string;
api: string; api: string;
cdn: string; cdn: string;
gateway: string; gateway: string;
login: string; login: string;
value: string; value: string;
}; }
if(instanceinfo){ if(instanceinfo){
instanceinfo.value = instanceValue; instanceinfo.value = instanceValue;
localStorage.setItem("instanceinfo", JSON.stringify(instanceinfo)); localStorage.setItem("instanceinfo", JSON.stringify(instanceinfo));
verify!.textContent = "Instance is all good"; verify!.textContent = "Instance is all good";
// @ts-ignore // @ts-ignore
if(checkInstance.alt){ if(checkInstance.alt){
// @ts-ignore // @ts-ignore
checkInstance.alt(); checkInstance.alt();
} }
setTimeout((_: any)=>{ setTimeout((_: any)=>{
console.log(verify!.textContent); console.log(verify!.textContent);
verify!.textContent = ""; verify!.textContent = "";
}, 3000); }, 3000);
}else{ }else{
verify!.textContent = "Invalid Instance, try again"; verify!.textContent = "Invalid Instance, try again";
} }
}catch{ }catch{
console.log("catch"); console.log("catch");
verify!.textContent = "Invalid Instance, try again"; verify!.textContent = "Invalid Instance, try again";
} }
} }
@ -569,24 +581,23 @@ export function getInstances(){
fetch("/instances.json") fetch("/instances.json")
.then(_=>_.json()) .then(_=>_.json())
.then( .then(
( (json: {
json: { name: string;
name: string; description?: string;
description?: string; descriptionLong?: string;
descriptionLong?: string; image?: string;
image?: string; url?: string;
url?: string; display?: boolean;
display?: boolean; online?: boolean;
online?: boolean; uptime: { alltime: number; daytime: number; weektime: number };
uptime: { alltime: number; daytime: number; weektime: number }; urls: {
urls: { wellknown: string;
wellknown: string; api: string;
api: string; cdn: string;
cdn: string; gateway: string;
gateway: string; login?: string;
login?: string; }
}; }[]
}[]
)=>{ )=>{
instances = json; instances = json;
if(datalist){ if(datalist){