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{
@@ -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);
@@ -323,7 +335,7 @@ async function checkInstance(instance?: 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));
@@ -569,8 +581,7 @@ 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;
@@ -585,7 +596,7 @@ fetch("/instances.json")
cdn: string; cdn: string;
gateway: string; gateway: string;
login?: string; login?: string;
}; }
}[] }[]
)=>{ )=>{
instances = json; instances = json;