diff --git a/web/assets/js/api.js b/web/assets/js/api.js index 4bc4014..2d93ef8 100644 --- a/web/assets/js/api.js +++ b/web/assets/js/api.js @@ -1,16 +1,19 @@ +// apiBase defines the base URL of the API +const apiBase = location.protocol + "//" + location.host + "/api/v1"; + // getAPIInformation returns the API information export async function getAPIInformation() { - return await fetch(location.protocol + "//" + location.host + "/api/v1/info"); + return fetch(apiBase + "/info"); } // getPaste retrieves a paste export async function getPaste(id) { - return await fetch(location.protocol + "//" + location.host + "/api/v1/pastes/" + id); + return fetch(apiBase + "/pastes/" + id); } // createPaste creates a new paste export async function createPaste(content) { - return await fetch(location.protocol + "//" + location.host + "/api/v1/pastes", { + return await fetch(apiBase + "/pastes", { method: 'POST', headers: { 'Content-Type': 'application/json' @@ -23,7 +26,7 @@ export async function createPaste(content) { // deletePaste deletes a paste export async function deletePaste(id, deletionToken) { - return await fetch(location.protocol + "//" + location.host + "/api/v1/pastes/" + id, { + return await fetch(apiBase + "/pastes/" + id, { method: 'DELETE', headers: { 'Content-Type': 'application/json' diff --git a/web/assets/js/autoload.js b/web/assets/js/autoload.js index 865f25a..e1b8dfd 100644 --- a/web/assets/js/autoload.js +++ b/web/assets/js/autoload.js @@ -20,7 +20,7 @@ loadAPIInformation(); // Try to load a paste if one exists export let PASTE_ID; async function loadPaste() { - if (location.pathname != "/") { + if (location.pathname !== "/") { // Define the paste ID and language const split = location.pathname.replace("/", "").split("."); const pasteID = split[0]; @@ -45,10 +45,7 @@ async function loadPaste() { : hljs.highlightAuto(data.content).value; // Display the line numbers - const lineNumbersElement = document.getElementById("linenos"); - data.content.split(/\n/).forEach(function(_currentValue, index) { - lineNumbersElement.innerHTML += "" + (index + 1) + ""; - }); + document.getElementById("linenos").innerHTML = data.content.split(/\n/).map((_, index) => `${index + 1}`).join(''); // Set the PASTE_ID variable PASTE_ID = pasteID; diff --git a/web/index.html b/web/index.html index ffcbed4..ec9803e 100644 --- a/web/index.html +++ b/web/index.html @@ -56,7 +56,7 @@
-
+
>