mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-11-22 14:38: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 request(method, path, body = null) {
|
||||
async function request(method, path, body = null) {
|
||||
var headers = {
|
||||
"Accept": "application/json"
|
||||
}
|
||||
|
@ -74,7 +73,3 @@ class Client {
|
|||
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
client = new Client();
|
||||
|
|
|
@ -15,7 +15,7 @@ async function handle_config_change(event) {
|
|||
}
|
||||
|
||||
try {
|
||||
await client.request("POST", "v1/config", params);
|
||||
await request("POST", "v1/config", params);
|
||||
|
||||
} catch (error) {
|
||||
alert(error);
|
||||
|
|
|
@ -33,7 +33,7 @@ async function ban() {
|
|||
}
|
||||
|
||||
try {
|
||||
var ban = await client.request("POST", "v1/domain_ban", values);
|
||||
var ban = await request("POST", "v1/domain_ban", values);
|
||||
|
||||
} catch (err) {
|
||||
alert(err);
|
||||
|
@ -69,7 +69,7 @@ async function update_ban(domain) {
|
|||
}
|
||||
|
||||
try {
|
||||
await client.request("PATCH", "v1/domain_ban", values)
|
||||
await request("PATCH", "v1/domain_ban", values)
|
||||
|
||||
} catch (error) {
|
||||
alert(error);
|
||||
|
@ -82,7 +82,7 @@ async function update_ban(domain) {
|
|||
|
||||
async function unban(domain) {
|
||||
try {
|
||||
await client.request("DELETE", "v1/domain_ban", {"domain": domain});
|
||||
await request("DELETE", "v1/domain_ban", {"domain": domain});
|
||||
|
||||
} catch (error) {
|
||||
alert(error);
|
||||
|
|
|
@ -19,7 +19,7 @@ async function add_instance() {
|
|||
}
|
||||
|
||||
try {
|
||||
var instance = await client.request("POST", "v1/instance", values);
|
||||
var instance = await request("POST", "v1/instance", values);
|
||||
|
||||
} catch (err) {
|
||||
alert(err);
|
||||
|
@ -44,7 +44,7 @@ async function add_instance() {
|
|||
|
||||
async function del_instance(domain) {
|
||||
try {
|
||||
await client.request("DELETE", "v1/instance", {"domain": domain});
|
||||
await request("DELETE", "v1/instance", {"domain": domain});
|
||||
|
||||
} catch (error) {
|
||||
alert(error);
|
||||
|
@ -62,7 +62,7 @@ async function req_response(domain, accept) {
|
|||
}
|
||||
|
||||
try {
|
||||
await client.request("POST", "v1/request", params);
|
||||
await request("POST", "v1/request", params);
|
||||
|
||||
} catch (error) {
|
||||
alert(error);
|
||||
|
@ -79,7 +79,7 @@ async function req_response(domain, accept) {
|
|||
return;
|
||||
}
|
||||
|
||||
instances = await client.request("GET", `v1/instance`, null);
|
||||
instances = await request("GET", `v1/instance`, null);
|
||||
instances.forEach((instance) => {
|
||||
if (instance.domain === domain) {
|
||||
append_table_row(document.getElementById("instances"), instance.domain, {
|
||||
|
|
|
@ -35,7 +35,7 @@ async function ban() {
|
|||
}
|
||||
|
||||
try {
|
||||
var ban = await client.request("POST", "v1/software_ban", values);
|
||||
var ban = await request("POST", "v1/software_ban", values);
|
||||
|
||||
} catch (err) {
|
||||
alert(err);
|
||||
|
@ -71,7 +71,7 @@ async function update_ban(name) {
|
|||
}
|
||||
|
||||
try {
|
||||
await client.request("PATCH", "v1/software_ban", values)
|
||||
await request("PATCH", "v1/software_ban", values)
|
||||
|
||||
} catch (error) {
|
||||
alert(error);
|
||||
|
@ -84,7 +84,7 @@ async function update_ban(name) {
|
|||
|
||||
async function unban(name) {
|
||||
try {
|
||||
await client.request("DELETE", "v1/software_ban", {"name": name});
|
||||
await request("DELETE", "v1/software_ban", {"name": name});
|
||||
|
||||
} catch (error) {
|
||||
alert(error);
|
||||
|
|
|
@ -24,7 +24,7 @@ async function add_user() {
|
|||
}
|
||||
|
||||
try {
|
||||
var user = await client.request("POST", "v1/user", values);
|
||||
var user = await request("POST", "v1/user", values);
|
||||
|
||||
} catch (err) {
|
||||
alert(err);
|
||||
|
@ -49,7 +49,7 @@ async function add_user() {
|
|||
|
||||
async function del_user(username) {
|
||||
try {
|
||||
await client.request("DELETE", "v1/user", {"username": username});
|
||||
await request("DELETE", "v1/user", {"username": username});
|
||||
|
||||
} catch (error) {
|
||||
alert(error);
|
||||
|
|
|
@ -8,16 +8,16 @@ async function add_whitelist() {
|
|||
}
|
||||
|
||||
try {
|
||||
var item = await client.request("POST", "v1/whitelist", {"domain": domain});
|
||||
var item = await request("POST", "v1/whitelist", {"domain": domain});
|
||||
|
||||
} catch (err) {
|
||||
alert(err);
|
||||
return
|
||||
}
|
||||
|
||||
append_table_row(document.getElementById("instances"), item.domain, {
|
||||
append_table_row(document.getElementById("whitelist"), 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>`
|
||||
});
|
||||
|
||||
|
@ -28,7 +28,7 @@ async function add_whitelist() {
|
|||
|
||||
async function del_whitelist(domain) {
|
||||
try {
|
||||
await client.request("DELETE", "v1/whitelist", {"domain": domain});
|
||||
await request("DELETE", "v1/whitelist", {"domain": domain});
|
||||
|
||||
} catch (error) {
|
||||
alert(error);
|
||||
|
|
Loading…
Reference in a new issue