fixed indents
This commit is contained in:
parent
2759ac82f9
commit
14d1c69c7d
1 changed files with 239 additions and 239 deletions
|
@ -662,261 +662,261 @@ class Localuser{
|
||||||
newbio=null;
|
newbio=null;
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
|
|
||||||
const connectionContainer=document.createElement("div");
|
const connectionContainer=document.createElement("div");
|
||||||
connectionContainer.id="connection-container";
|
connectionContainer.id="connection-container";
|
||||||
this.userConnections=new Fullscreen(
|
this.userConnections=new Fullscreen(
|
||||||
["html",
|
["html",
|
||||||
connectionContainer
|
connectionContainer
|
||||||
], () => {}, async () => {
|
], () => {}, async () => {
|
||||||
connectionContainer.innerHTML="";
|
connectionContainer.innerHTML="";
|
||||||
|
|
||||||
const res=await fetch(this.info.api.toString()+"/v9/connections", {
|
const res=await fetch(this.info.api.toString()+"/v9/connections", {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
});
|
});
|
||||||
const json=await res.json();
|
const json=await res.json();
|
||||||
|
|
||||||
Object.keys(json).sort(key => json[key].enabled ? -1 : 1).forEach(key => {
|
Object.keys(json).sort(key => json[key].enabled ? -1 : 1).forEach(key => {
|
||||||
const connection=json[key];
|
const connection=json[key];
|
||||||
|
|
||||||
const container=document.createElement("div");
|
const container=document.createElement("div");
|
||||||
container.textContent=key.charAt(0).toUpperCase() + key.slice(1);
|
container.textContent=key.charAt(0).toUpperCase() + key.slice(1);
|
||||||
|
|
||||||
if (connection.enabled) {
|
if (connection.enabled) {
|
||||||
container.addEventListener("click", async () => {
|
container.addEventListener("click", async () => {
|
||||||
const connectionRes=await fetch(this.info.api.toString()+"/v9/connections/" + key + "/authorize", {
|
const connectionRes=await fetch(this.info.api.toString()+"/v9/connections/" + key + "/authorize", {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
});
|
});
|
||||||
const connectionJSON=await connectionRes.json();
|
const connectionJSON=await connectionRes.json();
|
||||||
window.open(connectionJSON.url, "_blank", "noopener noreferrer");
|
window.open(connectionJSON.url, "_blank", "noopener noreferrer");
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
container.classList.add("disabled")
|
container.classList.add("disabled")
|
||||||
container.title="This connection has been disabled server-side."
|
container.title="This connection has been disabled server-side."
|
||||||
}
|
}
|
||||||
|
|
||||||
connectionContainer.appendChild(container);
|
connectionContainer.appendChild(container);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
let appName="";
|
let appName="";
|
||||||
const appListContainer=document.createElement("div");
|
const appListContainer=document.createElement("div");
|
||||||
appListContainer.id="app-list-container";
|
appListContainer.id="app-list-container";
|
||||||
this.devPortal=new Fullscreen(
|
this.devPortal=new Fullscreen(
|
||||||
["vdiv",
|
["vdiv",
|
||||||
["hdiv",
|
["hdiv",
|
||||||
["textbox", "Name:", appName, event => {
|
["textbox", "Name:", appName, event => {
|
||||||
appName=event.target.value;
|
appName=event.target.value;
|
||||||
}],
|
}],
|
||||||
["button",
|
["button",
|
||||||
"",
|
"",
|
||||||
"Create application",
|
"Create application",
|
||||||
async () => {
|
async () => {
|
||||||
if (appName.trim().length == 0) return alert("Please enter a name for the application.");
|
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.toString()+"/v9/applications", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
name: appName
|
name: appName
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
const json=await res.json();
|
const json=await res.json();
|
||||||
this.manageApplication(json.id);
|
this.manageApplication(json.id);
|
||||||
this.devPortal.hide();
|
this.devPortal.hide();
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
["html",
|
["html",
|
||||||
appListContainer
|
appListContainer
|
||||||
]
|
]
|
||||||
], () => {}, async () => {
|
], () => {}, async () => {
|
||||||
appListContainer.innerHTML="";
|
appListContainer.innerHTML="";
|
||||||
|
|
||||||
const res=await fetch(this.info.api.toString()+"/v9/applications", {
|
const res=await fetch(this.info.api.toString()+"/v9/applications", {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
});
|
});
|
||||||
const json=await res.json();
|
const json=await res.json();
|
||||||
|
|
||||||
json.forEach(application => {
|
json.forEach(application => {
|
||||||
const container=document.createElement("div");
|
const container=document.createElement("div");
|
||||||
|
|
||||||
if (application.cover_image) {
|
if (application.cover_image) {
|
||||||
const cover=document.createElement("img");
|
const cover=document.createElement("img");
|
||||||
cover.crossOrigin="anonymous";
|
cover.crossOrigin="anonymous";
|
||||||
cover.src=this.info.cdn.toString()+"/app-icons/" + application.id + "/" + application.cover_image + ".png?size=256";
|
cover.src=this.info.cdn.toString()+"/app-icons/" + application.id + "/" + application.cover_image + ".png?size=256";
|
||||||
cover.alt="";
|
cover.alt="";
|
||||||
cover.loading="lazy";
|
cover.loading="lazy";
|
||||||
container.appendChild(cover);
|
container.appendChild(cover);
|
||||||
}
|
}
|
||||||
|
|
||||||
const name=document.createElement("h2");
|
const name=document.createElement("h2");
|
||||||
name.textContent=application.name + (application.bot ? " (Bot)" : "");
|
name.textContent=application.name + (application.bot ? " (Bot)" : "");
|
||||||
container.appendChild(name);
|
container.appendChild(name);
|
||||||
|
|
||||||
container.addEventListener("click", async () => {
|
container.addEventListener("click", async () => {
|
||||||
this.devPortal.hide();
|
this.devPortal.hide();
|
||||||
this.manageApplication(application.id);
|
this.manageApplication(application.id);
|
||||||
});
|
});
|
||||||
appListContainer.appendChild(container);
|
appListContainer.appendChild(container);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
async manageApplication(appId="") {
|
async manageApplication(appId="") {
|
||||||
const res=await fetch(this.info.api.toString()+"/v9/applications/" + appId, {
|
const res=await fetch(this.info.api.toString()+"/v9/applications/" + appId, {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
});
|
});
|
||||||
const json=await res.json();
|
const json=await res.json();
|
||||||
|
|
||||||
const fields: any={};
|
const fields: any={};
|
||||||
const appDialog=new Fullscreen(
|
const appDialog=new Fullscreen(
|
||||||
["vdiv",
|
["vdiv",
|
||||||
["title",
|
["title",
|
||||||
"Editing " + json.name
|
"Editing " + json.name
|
||||||
],
|
],
|
||||||
["vdiv",
|
["vdiv",
|
||||||
["textbox", "Application name:", json.name, event => {
|
["textbox", "Application name:", json.name, event => {
|
||||||
fields.name=event.target.value;
|
fields.name=event.target.value;
|
||||||
}],
|
}],
|
||||||
["mdbox", "Description:", json.description, event => {
|
["mdbox", "Description:", json.description, event => {
|
||||||
fields.description=event.target.value;
|
fields.description=event.target.value;
|
||||||
}],
|
}],
|
||||||
["vdiv",
|
["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.toString()+"/app-icons/" + appId + "/" + json.icon + ".png?size=128", [128, 128]] : ["text", "No icon"],
|
||||||
["fileupload", "Application icon:", event => {
|
["fileupload", "Application icon:", event => {
|
||||||
const reader=new FileReader();
|
const reader=new FileReader();
|
||||||
reader.readAsDataURL(event.target.files[0]);
|
reader.readAsDataURL(event.target.files[0]);
|
||||||
reader.onload=() => {
|
reader.onload=() => {
|
||||||
fields.icon=reader.result;
|
fields.icon=reader.result;
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
["hdiv",
|
["hdiv",
|
||||||
["textbox", "Privacy policy URL:", json.privacy_policy_url || "", event => {
|
["textbox", "Privacy policy URL:", json.privacy_policy_url || "", event => {
|
||||||
fields.privacy_policy_url=event.target.value;
|
fields.privacy_policy_url=event.target.value;
|
||||||
}],
|
}],
|
||||||
["textbox", "Terms of Service URL:", json.terms_of_service_url || "", event => {
|
["textbox", "Terms of Service URL:", json.terms_of_service_url || "", event => {
|
||||||
fields.terms_of_service_url=event.target.value;
|
fields.terms_of_service_url=event.target.value;
|
||||||
}]
|
}]
|
||||||
],
|
],
|
||||||
["hdiv",
|
["hdiv",
|
||||||
["checkbox", "Make bot publicly inviteable?", json.bot_public, event => {
|
["checkbox", "Make bot publicly inviteable?", json.bot_public, event => {
|
||||||
fields.bot_public=event.target.checked;
|
fields.bot_public=event.target.checked;
|
||||||
}],
|
}],
|
||||||
["checkbox", "Require code grant to invite the bot?", json.bot_require_code_grant, event => {
|
["checkbox", "Require code grant to invite the bot?", json.bot_require_code_grant, event => {
|
||||||
fields.bot_require_code_grant=event.target.checked;
|
fields.bot_require_code_grant=event.target.checked;
|
||||||
}]
|
}]
|
||||||
],
|
],
|
||||||
["hdiv",
|
["hdiv",
|
||||||
["button",
|
["button",
|
||||||
"",
|
"",
|
||||||
"Save changes",
|
"Save changes",
|
||||||
async () => {
|
async () => {
|
||||||
const updateRes=await fetch(this.info.api.toString()+"/v9/applications/" + appId, {
|
const updateRes=await fetch(this.info.api.toString()+"/v9/applications/" + appId, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify(fields)
|
body: JSON.stringify(fields)
|
||||||
});
|
});
|
||||||
if (updateRes.ok) appDialog.hide();
|
if (updateRes.ok) appDialog.hide();
|
||||||
else {
|
else {
|
||||||
const updateJSON=await updateRes.json();
|
const updateJSON=await updateRes.json();
|
||||||
alert("An error occurred: " + updateJSON.message);
|
alert("An error occurred: " + updateJSON.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
["button",
|
["button",
|
||||||
"",
|
"",
|
||||||
(json.bot ? "Manage" : "Add") + " bot",
|
(json.bot ? "Manage" : "Add") + " bot",
|
||||||
async () => {
|
async () => {
|
||||||
if (!json.bot) {
|
if (!json.bot) {
|
||||||
if (!confirm("Are you sure you want to add a bot to this application? There's no going back.")) return;
|
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.toString()+"/v9/applications/" + appId + "/bot", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
});
|
});
|
||||||
const updateJSON=await updateRes.json();
|
const updateJSON=await updateRes.json();
|
||||||
alert("Bot token:\n" + updateJSON.token);
|
alert("Bot token:\n" + updateJSON.token);
|
||||||
}
|
}
|
||||||
|
|
||||||
appDialog.hide();
|
appDialog.hide();
|
||||||
this.manageBot(appId);
|
this.manageBot(appId);
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
appDialog.show();
|
appDialog.show();
|
||||||
}
|
}
|
||||||
async manageBot(appId="") {
|
async manageBot(appId="") {
|
||||||
const res=await fetch(this.info.api.toString()+"/v9/applications/" + appId, {
|
const res=await fetch(this.info.api.toString()+"/v9/applications/" + appId, {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
});
|
});
|
||||||
const json=await res.json();
|
const json=await res.json();
|
||||||
if (!json.bot) return alert("For some reason, this application doesn't have a bot (yet).");
|
if (!json.bot) return alert("For some reason, this application doesn't have a bot (yet).");
|
||||||
|
|
||||||
const fields: any={
|
const fields: any={
|
||||||
username: json.bot.username,
|
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.toString()+"/app-icons/" + appId + "/" + json.bot.avatar + ".png?size=256") : ""
|
||||||
};
|
};
|
||||||
const botDialog=new Fullscreen(
|
const botDialog=new Fullscreen(
|
||||||
["vdiv",
|
["vdiv",
|
||||||
["title",
|
["title",
|
||||||
"Editing bot: " + json.bot.username
|
"Editing bot: " + json.bot.username
|
||||||
],
|
],
|
||||||
["hdiv",
|
["hdiv",
|
||||||
["textbox", "Bot username:", json.bot.username, event => {
|
["textbox", "Bot username:", json.bot.username, event => {
|
||||||
fields.username=event.target.value
|
fields.username=event.target.value
|
||||||
}],
|
}],
|
||||||
["vdiv",
|
["vdiv",
|
||||||
fields.avatar ? ["img", fields.avatar, [128, 128]] : ["text", "No avatar"],
|
fields.avatar ? ["img", fields.avatar, [128, 128]] : ["text", "No avatar"],
|
||||||
["fileupload", "Bot avatar:", event => {
|
["fileupload", "Bot avatar:", event => {
|
||||||
const reader=new FileReader();
|
const reader=new FileReader();
|
||||||
reader.readAsDataURL(event.target.files[0]);
|
reader.readAsDataURL(event.target.files[0]);
|
||||||
reader.onload=() => {
|
reader.onload=() => {
|
||||||
fields.avatar=reader.result;
|
fields.avatar=reader.result;
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
["hdiv",
|
["hdiv",
|
||||||
["button",
|
["button",
|
||||||
"",
|
"",
|
||||||
"Save changes",
|
"Save changes",
|
||||||
async () => {
|
async () => {
|
||||||
const updateRes=await fetch(this.info.api.toString()+"/v9/applications/" + appId + "/bot", {
|
const updateRes=await fetch(this.info.api.toString()+"/v9/applications/" + appId + "/bot", {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify(fields)
|
body: JSON.stringify(fields)
|
||||||
});
|
});
|
||||||
if (updateRes.ok) botDialog.hide();
|
if (updateRes.ok) botDialog.hide();
|
||||||
else {
|
else {
|
||||||
const updateJSON=await updateRes.json();
|
const updateJSON=await updateRes.json();
|
||||||
alert("An error occurred: " + updateJSON.message);
|
alert("An error occurred: " + updateJSON.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
["button",
|
["button",
|
||||||
"",
|
"",
|
||||||
"Reset token",
|
"Reset token",
|
||||||
async () => {
|
async () => {
|
||||||
if (!confirm("Are you sure you want to reset the bot token? Your bot will stop working until you update it.")) return;
|
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.toString()+"/v9/applications/" + appId + "/bot/reset", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
});
|
});
|
||||||
const updateJSON=await updateRes.json();
|
const updateJSON=await updateRes.json();
|
||||||
alert("New token:\n" + updateJSON.token);
|
alert("New token:\n" + updateJSON.token);
|
||||||
botDialog.hide();
|
botDialog.hide();
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
botDialog.show();
|
botDialog.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export {Localuser};
|
export {Localuser};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue