mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-11-09 18:08:00 +00:00
move request method out of client class
This commit is contained in:
parent
0f3b72830b
commit
b068f4f91e
|
@ -33,8 +33,7 @@ function append_table_row(table, row_name, row) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Client {
|
async function request(method, path, body = null) {
|
||||||
async request(method, path, body = null) {
|
|
||||||
var headers = {
|
var headers = {
|
||||||
"Accept": "application/json"
|
"Accept": "application/json"
|
||||||
}
|
}
|
||||||
|
@ -73,8 +72,4 @@ class Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
client = new Client();
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ async function handle_config_change(event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.request("POST", "v1/config", params);
|
await request("POST", "v1/config", params);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(error);
|
alert(error);
|
||||||
|
|
|
@ -33,7 +33,7 @@ async function ban() {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var ban = await client.request("POST", "v1/domain_ban", values);
|
var ban = await request("POST", "v1/domain_ban", values);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert(err);
|
alert(err);
|
||||||
|
@ -69,7 +69,7 @@ async function update_ban(domain) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.request("PATCH", "v1/domain_ban", values)
|
await request("PATCH", "v1/domain_ban", values)
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(error);
|
alert(error);
|
||||||
|
@ -82,7 +82,7 @@ async function update_ban(domain) {
|
||||||
|
|
||||||
async function unban(domain) {
|
async function unban(domain) {
|
||||||
try {
|
try {
|
||||||
await client.request("DELETE", "v1/domain_ban", {"domain": domain});
|
await request("DELETE", "v1/domain_ban", {"domain": domain});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(error);
|
alert(error);
|
||||||
|
|
|
@ -19,7 +19,7 @@ async function add_instance() {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var instance = await client.request("POST", "v1/instance", values);
|
var instance = await request("POST", "v1/instance", values);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert(err);
|
alert(err);
|
||||||
|
@ -44,7 +44,7 @@ async function add_instance() {
|
||||||
|
|
||||||
async function del_instance(domain) {
|
async function del_instance(domain) {
|
||||||
try {
|
try {
|
||||||
await client.request("DELETE", "v1/instance", {"domain": domain});
|
await request("DELETE", "v1/instance", {"domain": domain});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(error);
|
alert(error);
|
||||||
|
@ -62,7 +62,7 @@ async function req_response(domain, accept) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.request("POST", "v1/request", params);
|
await request("POST", "v1/request", params);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(error);
|
alert(error);
|
||||||
|
@ -79,7 +79,7 @@ async function req_response(domain, accept) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
instances = await client.request("GET", `v1/instance`, null);
|
instances = await request("GET", `v1/instance`, null);
|
||||||
instances.forEach((instance) => {
|
instances.forEach((instance) => {
|
||||||
if (instance.domain === domain) {
|
if (instance.domain === domain) {
|
||||||
append_table_row(document.getElementById("instances"), instance.domain, {
|
append_table_row(document.getElementById("instances"), instance.domain, {
|
||||||
|
|
|
@ -35,7 +35,7 @@ async function ban() {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var ban = await client.request("POST", "v1/software_ban", values);
|
var ban = await request("POST", "v1/software_ban", values);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert(err);
|
alert(err);
|
||||||
|
@ -71,7 +71,7 @@ async function update_ban(name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.request("PATCH", "v1/software_ban", values)
|
await request("PATCH", "v1/software_ban", values)
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(error);
|
alert(error);
|
||||||
|
@ -84,7 +84,7 @@ async function update_ban(name) {
|
||||||
|
|
||||||
async function unban(name) {
|
async function unban(name) {
|
||||||
try {
|
try {
|
||||||
await client.request("DELETE", "v1/software_ban", {"name": name});
|
await request("DELETE", "v1/software_ban", {"name": name});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(error);
|
alert(error);
|
||||||
|
|
|
@ -24,7 +24,7 @@ async function add_user() {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var user = await client.request("POST", "v1/user", values);
|
var user = await request("POST", "v1/user", values);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert(err);
|
alert(err);
|
||||||
|
@ -49,7 +49,7 @@ async function add_user() {
|
||||||
|
|
||||||
async function del_user(username) {
|
async function del_user(username) {
|
||||||
try {
|
try {
|
||||||
await client.request("DELETE", "v1/user", {"username": username});
|
await request("DELETE", "v1/user", {"username": username});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(error);
|
alert(error);
|
||||||
|
|
|
@ -8,16 +8,16 @@ async function add_whitelist() {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var item = await client.request("POST", "v1/whitelist", {"domain": domain});
|
var item = await request("POST", "v1/whitelist", {"domain": domain});
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert(err);
|
alert(err);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
append_table_row(document.getElementById("instances"), item.domain, {
|
append_table_row(document.getElementById("whitelist"), item.domain, {
|
||||||
domain: item.domain,
|
domain: item.domain,
|
||||||
date: get_date_string(ban.created),
|
date: get_date_string(item.created),
|
||||||
remove: `<a href="#" onclick="del_whitelist('${item.domain}')" title="Remove whitelisted domain">✖</a>`
|
remove: `<a href="#" onclick="del_whitelist('${item.domain}')" title="Remove whitelisted domain">✖</a>`
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ async function add_whitelist() {
|
||||||
|
|
||||||
async function del_whitelist(domain) {
|
async function del_whitelist(domain) {
|
||||||
try {
|
try {
|
||||||
await client.request("DELETE", "v1/whitelist", {"domain": domain});
|
await request("DELETE", "v1/whitelist", {"domain": domain});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(error);
|
alert(error);
|
||||||
|
|
Loading…
Reference in a new issue