diff --git a/web/assets/js/api.js b/web/assets/js/api.js index 2d93ef8..cc2d64c 100644 --- a/web/assets/js/api.js +++ b/web/assets/js/api.js @@ -1,5 +1,5 @@ // apiBase defines the base URL of the API -const apiBase = location.protocol + "//" + location.host + "/api/v1"; +const apiBase = location.protocol + "//" + location.host + "/api/v2"; // getAPIInformation returns the API information export async function getAPIInformation() { @@ -25,14 +25,12 @@ export async function createPaste(content) { } // deletePaste deletes a paste -export async function deletePaste(id, deletionToken) { +export async function deletePaste(id, modificationToken) { return await fetch(apiBase + "/pastes/" + id, { method: 'DELETE', headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - deletionToken - }) + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ' + modificationToken, + } }); } \ No newline at end of file diff --git a/web/assets/js/buttons.js b/web/assets/js/buttons.js index b246c81..42d6597 100644 --- a/web/assets/js/buttons.js +++ b/web/assets/js/buttons.js @@ -12,20 +12,20 @@ export function setupKeybinds() { // Define the DOM element of the pressed button let element = null; - switch (event.keyCode) { - case 81: { + switch (event.code) { + case "KeyQ": { element = document.getElementById("btn_new"); break; } - case 83: { + case "KeyS": { element = document.getElementById("btn_save"); break; } - case 88: { + case "KeyX": { element = document.getElementById("btn_delete"); break; } - case 66: { + case "KeyB": { element = document.getElementById("btn_copy"); break; } @@ -62,14 +62,13 @@ export function setupButtons() { } const data = await response.json(); - // Give the user the chance to copy the deletion token - if (data.deletionToken) { - prompt("The deletion token for your paste is:", data.deletionToken); + // Give the user the chance to copy the modification token + if (data.modificationToken) { + prompt("The modification token for your paste is:", data.modificationToken); } // Redirect the user to the paste page let address = location.protocol + "//" + location.host + "/" + data.id; - if (data.suggestedSyntaxType) address += "." + data.suggestedSyntaxType; location.replace(address); }); }); @@ -77,12 +76,12 @@ export function setupButtons() { // Define the behavior of the 'delete' button document.getElementById("btn_delete").addEventListener("click", function () { spinner.surround(async function () { - // Ask the user for the deletion token - const deletionToken = prompt("Deletion Token:"); - if (!deletionToken) return; + // Ask the user for the modification token + const modificationToken = prompt("Modification Token:"); + if (!modificationToken) return; // Delete the paste - const response = await api.deletePaste(autoload.PASTE_ID, deletionToken); + const response = await api.deletePaste(autoload.PASTE_ID, modificationToken); const data = await response.text(); if (!response.ok) { notifications.error("Failed deleting the paste: " + data + "");