1
0
mirror of https://github.com/lus/pasty.git synced 2023-08-10 21:13:09 +03:00

Improve some frontend stuff

This commit is contained in:
Lukas SP 2020-08-24 21:53:23 +02:00
parent 55e65f5ecf
commit 98cf1b396e
3 changed files with 10 additions and 10 deletions

View File

@ -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 // getAPIInformation returns the API information
export async function getAPIInformation() { export async function getAPIInformation() {
return await fetch(location.protocol + "//" + location.host + "/api/v1/info"); return fetch(apiBase + "/info");
} }
// getPaste retrieves a paste // getPaste retrieves a paste
export async function getPaste(id) { 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 // createPaste creates a new paste
export async function createPaste(content) { export async function createPaste(content) {
return await fetch(location.protocol + "//" + location.host + "/api/v1/pastes", { return await fetch(apiBase + "/pastes", {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
@ -23,7 +26,7 @@ export async function createPaste(content) {
// deletePaste deletes a paste // deletePaste deletes a paste
export async function deletePaste(id, deletionToken) { 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', method: 'DELETE',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'

View File

@ -20,7 +20,7 @@ loadAPIInformation();
// Try to load a paste if one exists // Try to load a paste if one exists
export let PASTE_ID; export let PASTE_ID;
async function loadPaste() { async function loadPaste() {
if (location.pathname != "/") { if (location.pathname !== "/") {
// Define the paste ID and language // Define the paste ID and language
const split = location.pathname.replace("/", "").split("."); const split = location.pathname.replace("/", "").split(".");
const pasteID = split[0]; const pasteID = split[0];
@ -45,10 +45,7 @@ async function loadPaste() {
: hljs.highlightAuto(data.content).value; : hljs.highlightAuto(data.content).value;
// Display the line numbers // Display the line numbers
const lineNumbersElement = document.getElementById("linenos"); document.getElementById("linenos").innerHTML = data.content.split(/\n/).map((_, index) => `<span>${index + 1}</span>`).join('');
data.content.split(/\n/).forEach(function(_currentValue, index) {
lineNumbersElement.innerHTML += "<span>" + (index + 1) + "</span>";
});
// Set the PASTE_ID variable // Set the PASTE_ID variable
PASTE_ID = pasteID; PASTE_ID = pasteID;

View File

@ -56,7 +56,7 @@
</div> </div>
</div> </div>
<div class="container"> <div class="container">
<div id="linenos"></div> <div id="linenos"><span>></span></div>
<div id="content"> <div id="content">
<div id="code"></div> <div id="code"></div>
<textarea id="input" class="hidden"></textarea> <textarea id="input" class="hidden"></textarea>