mirror of
https://github.com/lus/pasty.git
synced 2023-08-10 21:13:09 +03:00
Improve the frontend (API v2 functionalities) (#18)
* Fix line number height issue * Fix notification container position * Remove line wrapping * Switch to the new API * Rework JS & implement paste editing * Implement paste reports * Document the report webhook
This commit is contained in:
committed by
GitHub
parent
149abf77f1
commit
70c4392390
57
web/assets/js/modules/api.js
Normal file
57
web/assets/js/modules/api.js
Normal file
@@ -0,0 +1,57 @@
|
||||
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
|
||||
})
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user