1
0
mirror of https://github.com/lus/pasty.git synced 2023-08-10 21:13:09 +03:00
pasty/web/assets/js/modules/api.js
2021-10-15 17:51:02 +02:00

58 lines
1.5 KiB
JavaScript

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) {
return fetch(API_BASE_URL + "/pastes", {
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
})
});
}