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:
parent
55e65f5ecf
commit
98cf1b396e
@ -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'
|
||||
|
@ -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 += "<span>" + (index + 1) + "</span>";
|
||||
});
|
||||
document.getElementById("linenos").innerHTML = data.content.split(/\n/).map((_, index) => `<span>${index + 1}</span>`).join('');
|
||||
|
||||
// Set the PASTE_ID variable
|
||||
PASTE_ID = pasteID;
|
||||
|
@ -56,7 +56,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
<div id="linenos"></div>
|
||||
<div id="linenos"><span>></span></div>
|
||||
<div id="content">
|
||||
<div id="code"></div>
|
||||
<textarea id="input" class="hidden"></textarea>
|
||||
|
Loading…
Reference in New Issue
Block a user