rename routes to make more sense

for example, /getInvite and /generateInvite become GET(/invites) and
    POST(/invites) respectively.
This commit is contained in:
Harvey Tindall
2020-09-24 14:03:25 +01:00
parent ce844e0574
commit 544f5674e8
19 changed files with 62 additions and 1673 deletions
+4 -4
View File
@@ -47,7 +47,7 @@ function changeEmail(icon: HTMLElement, id: string): void {
tick.replaceWith(spinner);
let send = {};
send[id] = newEmail;
_post("/modifyEmails", send, function (): void {
_post("/users/emails", send, function (): void {
if (this.readyState == 4) {
if (this.status == 200 || this.status == 204) {
entry.nextElementSibling.remove();
@@ -123,7 +123,7 @@ function populateUsers(): void {
`;
};
_get("/getUsers", null, function (): void {
_get("/users", null, function (): void {
if (this.readyState == 4 && this.status == 200) {
jfUsers = this.response['users'];
for (const user of jfUsers) {
@@ -206,7 +206,7 @@ function populateRadios(): void {
'notify': dmNotify.checked,
'reason': dmReason.value
};
_post("/deleteUser", send, function (): void {
_delete("/users", send, function (): void {
if (this.readyState == 4) {
if (this.status == 500) {
if ("error" in this.reponse) {
@@ -301,7 +301,7 @@ function populateRadios(): void {
'password': password,
'email': email
};
_post("/newUserAdmin", send, function (): void {
_post("/users", send, function (): void {
if (this.readyState == 4) {
rmAttr(button, 'btn-primary');
if (this.status == 200) {
+19 -10
View File
@@ -5,15 +5,6 @@ interface Window {
// Set in admin.html
var cssFile: string;
const _post = (url: string, data: Object, onreadystatechange: () => void): void => {
let req = new XMLHttpRequest();
req.open("POST", url, true);
req.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
req.onreadystatechange = onreadystatechange;
req.send(JSON.stringify(data));
};
const _get = (url: string, data: Object, onreadystatechange: () => void): void => {
let req = new XMLHttpRequest();
req.open("GET", url, true);
@@ -24,6 +15,24 @@ const _get = (url: string, data: Object, onreadystatechange: () => void): void =
req.send(JSON.stringify(data));
};
const _post = (url: string, data: Object, onreadystatechange: () => void): void => {
let req = new XMLHttpRequest();
req.open("POST", url, true);
req.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
req.onreadystatechange = onreadystatechange;
req.send(JSON.stringify(data));
};
function _delete(url: string, data: Object, onreadystatechange: () => void): void {
let req = new XMLHttpRequest();
req.open("DELETE", url, true);
req.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
req.onreadystatechange = onreadystatechange;
req.send(JSON.stringify(data));
}
const rmAttr = (el: HTMLElement, attr: string): void => {
if (el.classList.contains(attr)) {
el.classList.remove(attr);
@@ -222,7 +231,7 @@ function storeDefaults(users: string | Array<string>): void {
if ((document.getElementById('storeDefaultHomescreen') as HTMLInputElement).checked) {
data["homescreen"] = true;
}
_post("/applySettings", data, function (): void {
_post("/users/settings", data, function (): void {
if (this.readyState == 4) {
if (this.status == 200 || this.status == 204) {
button.textContent = "Success";
+5 -5
View File
@@ -65,7 +65,7 @@ function setNotify(el: HTMLElement): void {
}
send[code] = {};
send[code][notifyType] = (el as HTMLInputElement).checked;
_post("/setNotify", send, function (): void {
_post("/invites/notify", send, function (): void {
if (this.readyState == 4 && this.status != 200) {
(el as HTMLInputElement).checked = !(el as HTMLInputElement).checked;
}
@@ -217,7 +217,7 @@ function updateInvite(invite: Invite): void {
const hideInvite = (code: string): void => document.getElementById(CSS.escape(code)).remove();
// delete invite from jfa-go
const deleteInvite = (code: string): void => _post("/deleteInvite", { "code": code }, function (): void {
const deleteInvite = (code: string): void => _delete("/invites", { "code": code }, function (): void {
if (this.readyState == 4) {
generateInvites();
}
@@ -229,7 +229,7 @@ function generateInvites(empty?: boolean): void {
addItem(emptyInvite());
return;
}
_get("/getInvites", null, function (): void {
_get("/invites", null, function (): void {
if (this.readyState == 4) {
let data = this.response;
availableProfiles = data['profiles'];
@@ -330,7 +330,7 @@ fixCheckboxes();
delete send['send_to_address_enabled'];
}
console.log(send);
_post("/generateInvite", send, function (): void {
_post("/invites", send, function (): void {
if (this.readyState == 4) {
button.textContent = 'Generate';
button.disabled = false;
@@ -355,7 +355,7 @@ function setProfile(select: HTMLSelectElement): void {
"invite": invite,
"profile": val
};
_post("/setProfile", send, function (): void {
_post("/invites/profile", send, function (): void {
if (this.readyState == 4 && this.status != 200) {
generateInvites();
}
+2 -2
View File
@@ -6,7 +6,7 @@ const ombiDefaultsModal = createModal('ombiDefaults');
button.innerHTML =
'<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="margin-right: 0.5rem;"></span>' +
'Loading...';
_get("/getOmbiUsers", null, function (): void {
_get("/ombi/users", null, function (): void {
if (this.readyState == 4) {
if (this.status == 200) {
const users = this.response['users'];
@@ -52,7 +52,7 @@ const ombiDefaultsModal = createModal('ombiDefaults');
const data = {
"id": radio.id.replace("ombiDefault_", "")
};
_post("/setOmbiDefaults", data, function (): void {
_post("/ombi/defaults", data, function (): void {
if (this.readyState == 4) {
if (this.status == 200 || this.status == 204) {
button.textContent = "Success";
+7 -7
View File
@@ -3,7 +3,7 @@ var modifiedConfig: Object = {};
function sendConfig(restart?: boolean): void {
modifiedConfig["restart-program"] = restart;
_post("/modifyConfig", modifiedConfig, function (): void {
_post("/config", modifiedConfig, function (): void {
if (this.readyState == 4) {
const save = document.getElementById("settingsSave") as HTMLButtonElement
if (this.status == 200 || this.status == 204) {
@@ -29,7 +29,7 @@ function sendConfig(restart?: boolean): void {
aboutModal.show();
};
const openSettings = (settingsList: HTMLElement, settingsContent: HTMLElement, callback?: () => void): void => _get("/getConfig", null, function (): void {
const openSettings = (settingsList: HTMLElement, settingsContent: HTMLElement, callback?: () => void): void => _get("/config", null, function (): void {
if (this.readyState == 4 && this.status == 200) {
settingsList.textContent = '';
config = this.response;
@@ -139,7 +139,7 @@ interface Profile {
(document.getElementById('profiles_button') as HTMLButtonElement).onclick = (): void => showSetting("profiles", populateProfiles);
const populateProfiles = (noTable?: boolean): void => _get("/getProfiles", null, function (): void {
const populateProfiles = (noTable?: boolean): void => _get("/profiles", null, function (): void {
if (this.readyState == 4 && this.status == 200) {
const profileList = document.getElementById('profileList');
profileList.textContent = '';
@@ -167,7 +167,7 @@ const populateProfiles = (noTable?: boolean): void => _get("/getProfiles", null,
}
});
const setDefaultProfile = (name: string): void => _post("/setDefaultProfile", { "name": name }, function (): void {
const setDefaultProfile = (name: string): void => _post("/profiles/default", { "name": name }, function (): void {
if (this.readyState == 4) {
if (this.status != 200) {
(document.getElementById(`defaultProfile_${availableProfiles[0]}`) as HTMLInputElement).checked = true;
@@ -178,13 +178,13 @@ const setDefaultProfile = (name: string): void => _post("/setDefaultProfile", {
}
});
const deleteProfile = (name: string): void => _post("/deleteProfile", { "name": name }, function (): void {
const deleteProfile = (name: string): void => _delete("/profiles", { "name": name }, function (): void {
if (this.readyState == 4 && this.status == 200) {
populateProfiles();
}
});
const createProfile = (): void => _get("/getUsers", null, function (): void {
const createProfile = (): void => _get("/users", null, function (): void {
if (this.readyState == 4 && this.status == 200) {
jfUsers = this.response["users"];
populateRadios();
@@ -225,7 +225,7 @@ function storeProfile(): void {
if ((document.getElementById('storeDefaultHomescreen') as HTMLInputElement).checked) {
data["homescreen"] = true;
}
_post("/createProfile", data, function (): void {
_post("/profiles", data, function (): void {
if (this.readyState == 4) {
if (this.status == 200 || this.status == 204) {
button.textContent = "Success";