fix url bugs and improve account switcher

This commit is contained in:
MathMan05 2024-08-11 15:16:49 -05:00
parent 0fe2966ad1
commit 5148e1b77b
19 changed files with 186 additions and 175 deletions

View file

@ -18,9 +18,9 @@ class Localuser{
lastSequence:number|null=null;
token:string;
userinfo:Specialuser;
serverurls;
serverurls:Specialuser["serverurls"];
initialized:boolean;
info;
info:Specialuser["serverurls"];
headers:{"Content-type":string,Authorization:string};
usersettings:Settings;
userConnections:Fullscreen;
@ -487,7 +487,7 @@ class Localuser{
}else{
parsed=inviteurl;
}
fetch(this.info.api.toString()+"/v9/invites/"+parsed,{
fetch(this.info.api+"/v9/invites/"+parsed,{
method:"POST",
headers:this.headers,
}).then(r=>r.json()).then(_=>{
@ -512,7 +512,7 @@ class Localuser{
const full=new Fullscreen(["html", content]);
full.show();
const res=await fetch(this.info.api.toString()+"/v9/discoverable-guilds?limit=50", {
const res=await fetch(this.info.api+"/v9/discoverable-guilds?limit=50", {
headers: this.headers
});
const json=await res.json();
@ -533,7 +533,7 @@ class Localuser{
const banner=document.createElement("img");
banner.classList.add("banner");
banner.crossOrigin="anonymous";
banner.src=this.info.cdn.toString()+"icons/"+guild.id+"/"+guild.banner+".png?size=256";
banner.src=this.info.cdn+"icons/"+guild.id+"/"+guild.banner+".png?size=256";
banner.alt="";
content.appendChild(banner);
}
@ -543,7 +543,7 @@ class Localuser{
const img=document.createElement("img");
img.classList.add("icon");
img.crossOrigin="anonymous";
img.src=this.info.cdn.toString()+(guild.icon ? ("/icons/"+guild.id+"/"+guild.icon+".png?size=48") : "/embed/avatars/3.png");
img.src=this.info.cdn+(guild.icon ? ("/icons/"+guild.id+"/"+guild.icon+".png?size=48") : "/embed/avatars/3.png");
img.alt="";
nameContainer.appendChild(img);
@ -556,7 +556,7 @@ class Localuser{
content.appendChild(desc);
content.addEventListener("click", async ()=>{
const joinRes=await fetch(this.info.api.toString()+"/v9/guilds/"+guild.id+"/members/@me", {
const joinRes=await fetch(this.info.api+"/v9/guilds/"+guild.id+"/members/@me", {
method: "PUT",
headers: this.headers
});
@ -611,7 +611,7 @@ class Localuser{
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = ()=>{
fetch(this.info.api.toString()+"/users/@me",{
fetch(this.info.api+"/users/@me",{
method:"PATCH",
headers:this.headers,
body:JSON.stringify({
@ -622,7 +622,7 @@ class Localuser{
}
updatepronouns(pronouns:string):void{
fetch(this.info.api.toString()+"/users/@me/profile",{
fetch(this.info.api+"/users/@me/profile",{
method:"PATCH",
headers:this.headers,
body:JSON.stringify({
@ -631,7 +631,7 @@ class Localuser{
});
}
updatebio(bio:string):void{
fetch(this.info.api.toString()+"/v9/users/@me/profile",{
fetch(this.info.api+"/v9/users/@me/profile",{
method:"PATCH",
headers:this.headers,
body:JSON.stringify({
@ -755,7 +755,7 @@ class Localuser{
const security=settings.addButton("Account Security");
if(this.mfa_enabled){
security.addTextInput("Disable 2FA, totp code:",_=>{
fetch(this.info.api.toString()+"/users/@me/mfa/totp/disable",{
fetch(this.info.api+"/users/@me/mfa/totp/disable",{
method:"POST",
headers:this.headers,
body:JSON.stringify({
@ -786,7 +786,7 @@ class Localuser{
["textbox","Account password:","",function(){password=this.value}],
["textbox","Code:","",function(){code=this.value}],
["button","","Submit",()=>{
fetch(this.info.api.toString()+"/users/@me/mfa/totp/enable/",{
fetch(this.info.api+"/users/@me/mfa/totp/enable/",{
method:"POST",
headers:this.headers,
body:JSON.stringify({
@ -826,7 +826,7 @@ class Localuser{
], () => {}, async () => {
connectionContainer.innerHTML="";
const res=await fetch(this.info.api.toString()+"/v9/connections", {
const res=await fetch(this.info.api+"/v9/connections", {
headers: this.headers
});
const json=await res.json();
@ -839,7 +839,7 @@ class Localuser{
if (connection.enabled) {
container.addEventListener("click", async () => {
const connectionRes=await fetch(this.info.api.toString()+"/v9/connections/" + key + "/authorize", {
const connectionRes=await fetch(this.info.api+"/v9/connections/" + key + "/authorize", {
headers: this.headers
});
const connectionJSON=await connectionRes.json();
@ -870,7 +870,7 @@ class Localuser{
async () => {
if (appName.trim().length == 0) return alert("Please enter a name for the application.");
const res=await fetch(this.info.api.toString()+"/v9/applications", {
const res=await fetch(this.info.api+"/v9/applications", {
method: "POST",
headers: this.headers,
body: JSON.stringify({
@ -889,7 +889,7 @@ class Localuser{
], () => {}, async () => {
appListContainer.innerHTML="";
const res=await fetch(this.info.api.toString()+"/v9/applications", {
const res=await fetch(this.info.api+"/v9/applications", {
headers: this.headers
});
const json=await res.json();
@ -900,7 +900,7 @@ class Localuser{
if (application.cover_image) {
const cover=document.createElement("img");
cover.crossOrigin="anonymous";
cover.src=this.info.cdn.toString()+"/app-icons/" + application.id + "/" + application.cover_image + ".png?size=256";
cover.src=this.info.cdn+"/app-icons/" + application.id + "/" + application.cover_image + ".png?size=256";
cover.alt="";
cover.loading="lazy";
container.appendChild(cover);
@ -920,7 +920,7 @@ class Localuser{
)
}
async manageApplication(appId="") {
const res=await fetch(this.info.api.toString()+"/v9/applications/" + appId, {
const res=await fetch(this.info.api+"/v9/applications/" + appId, {
headers: this.headers
});
const json=await res.json();
@ -939,7 +939,7 @@ class Localuser{
fields.description=event.target.value;
}],
["vdiv",
json.icon ? ["img", this.info.cdn.toString()+"/app-icons/" + appId + "/" + json.icon + ".png?size=128", [128, 128]] : ["text", "No icon"],
json.icon ? ["img", this.info.cdn+"/app-icons/" + appId + "/" + json.icon + ".png?size=128", [128, 128]] : ["text", "No icon"],
["fileupload", "Application icon:", event => {
const reader=new FileReader();
reader.readAsDataURL(event.target.files[0]);
@ -970,7 +970,7 @@ class Localuser{
"",
"Save changes",
async () => {
const updateRes=await fetch(this.info.api.toString()+"/v9/applications/" + appId, {
const updateRes=await fetch(this.info.api+"/v9/applications/" + appId, {
method: "PATCH",
headers: this.headers,
body: JSON.stringify(fields)
@ -989,7 +989,7 @@ class Localuser{
if (!json.bot) {
if (!confirm("Are you sure you want to add a bot to this application? There's no going back.")) return;
const updateRes=await fetch(this.info.api.toString()+"/v9/applications/" + appId + "/bot", {
const updateRes=await fetch(this.info.api+"/v9/applications/" + appId + "/bot", {
method: "POST",
headers: this.headers
});
@ -1007,7 +1007,7 @@ class Localuser{
appDialog.show();
}
async manageBot(appId="") {
const res=await fetch(this.info.api.toString()+"/v9/applications/" + appId, {
const res=await fetch(this.info.api+"/v9/applications/" + appId, {
headers: this.headers
});
const json=await res.json();
@ -1015,7 +1015,7 @@ class Localuser{
const fields: any={
username: json.bot.username,
avatar: json.bot.avatar ? (this.info.cdn.toString()+"/app-icons/" + appId + "/" + json.bot.avatar + ".png?size=256") : ""
avatar: json.bot.avatar ? (this.info.cdn+"/app-icons/" + appId + "/" + json.bot.avatar + ".png?size=256") : ""
};
const botDialog=new Fullscreen(
["vdiv",
@ -1042,7 +1042,7 @@ class Localuser{
"",
"Save changes",
async () => {
const updateRes=await fetch(this.info.api.toString()+"/v9/applications/" + appId + "/bot", {
const updateRes=await fetch(this.info.api+"/v9/applications/" + appId + "/bot", {
method: "PATCH",
headers: this.headers,
body: JSON.stringify(fields)
@ -1060,7 +1060,7 @@ class Localuser{
async () => {
if (!confirm("Are you sure you want to reset the bot token? Your bot will stop working until you update it.")) return;
const updateRes=await fetch(this.info.api.toString()+"/v9/applications/" + appId + "/bot/reset", {
const updateRes=await fetch(this.info.api+"/v9/applications/" + appId + "/bot/reset", {
method: "POST",
headers: this.headers
});