2021-07-24 00:39:37 +03:00
|
|
|
const API_BASE_URL = location.protocol + "//" + location.host + "/api/v2";
|
|
|
|
|
|
|
|
export async function getAPIInformation() {
|
|
|
|
return fetch(API_BASE_URL + "/info");
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getPaste(pasteID) {
|
|
|
|
return fetch(API_BASE_URL + "/pastes/" + pasteID);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function createPaste(content, metadata) {
|
2021-10-15 18:51:02 +03:00
|
|
|
return fetch(API_BASE_URL + "/pastes", {
|
2021-07-24 00:39:37 +03:00
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
content,
|
|
|
|
metadata
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function editPaste(pasteID, modificationToken, content, metadata) {
|
|
|
|
return fetch(API_BASE_URL + "/pastes/" + pasteID, {
|
|
|
|
method: "PATCH",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
"Authorization": "Bearer " + modificationToken,
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
content,
|
|
|
|
metadata
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function deletePaste(pasteID, modificationToken) {
|
|
|
|
return fetch(API_BASE_URL + "/pastes/" + pasteID, {
|
|
|
|
method: "DELETE",
|
|
|
|
headers: {
|
|
|
|
"Authorization": "Bearer " + modificationToken,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function reportPaste(pasteID, reason) {
|
|
|
|
return fetch(API_BASE_URL + "/pastes/" + pasteID + "/report", {
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
reason
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|