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

undo accidental string replacements

This commit is contained in:
Lukas Schulte Pelkum 2023-06-08 19:27:27 +02:00
parent 4ce806945d
commit a24be8b2ff
No known key found for this signature in database
GPG Key ID: AB3985CECFAFC962
2 changed files with 24 additions and 24 deletions

View File

@ -1,4 +1,4 @@
const API_BASE_URL = location.protocol + "//" + location.host + "/web/v2"; const API_BASE_URL = location.protocol + "//" + location.host + "/api/v2";
export async function getAPIInformation() { export async function getAPIInformation() {
return fetch(API_BASE_URL + "/info"); return fetch(API_BASE_URL + "/info");

View File

@ -64,20 +64,20 @@ export async function initialize() {
} }
if (location.pathname !== "/") { if (location.pathname !== "/") {
// Extract the pastes data (ID and language) // Extract the paste data (ID and language)
const split = location.pathname.replace("/", "").split("."); const split = location.pathname.replace("/", "").split(".");
const pasteID = split[0]; const pasteID = split[0];
const language = split[1]; const language = split[1];
// Try to retrieve the pastes data from the API // Try to retrieve the paste data from the API
const response = await API.getPaste(pasteID); const response = await API.getPaste(pasteID);
if (!response.ok) { if (!response.ok) {
Notifications.error("Could not load pastes: <b>" + await response.text() + "</b>"); Notifications.error("Could not load paste: <b>" + await response.text() + "</b>");
setTimeout(() => location.replace(location.protocol + "//" + location.host), 3000); setTimeout(() => location.replace(location.protocol + "//" + location.host), 3000);
return; return;
} }
// Set the persistent pastes data // Set the persistent paste data
PASTE_ID = pasteID; PASTE_ID = pasteID;
LANGUAGE = language; LANGUAGE = language;
@ -95,7 +95,7 @@ export async function initialize() {
ENCRYPTION_IV = json.metadata.pf_encryption.iv; ENCRYPTION_IV = json.metadata.pf_encryption.iv;
} catch (error) { } catch (error) {
console.log(error); console.log(error);
Notifications.error("Could not decrypt pastes; make sure the decryption key is correct."); Notifications.error("Could not decrypt paste; make sure the decryption key is correct.");
setTimeout(() => location.replace(location.protocol + "//" + location.host), 3000); setTimeout(() => location.replace(location.protocol + "//" + location.host), 3000);
return; return;
} }
@ -104,7 +104,7 @@ export async function initialize() {
// Fill the code block with the just received data // Fill the code block with the just received data
updateCode(); updateCode();
} else { } else {
// Give the user the opportunity to pastes his code // Give the user the opportunity to paste his code
INPUT_ELEMENT.classList.remove("hidden"); INPUT_ELEMENT.classList.remove("hidden");
INPUT_ELEMENT.focus(); INPUT_ELEMENT.focus();
LIFETIME_CONTAINER_ELEMENT.classList.remove("hidden"); LIFETIME_CONTAINER_ELEMENT.classList.remove("hidden");
@ -138,7 +138,7 @@ async function loadAPIInformation() {
// Display the API version // Display the API version
document.getElementById("version").innerText = API_INFORMATION.version; document.getElementById("version").innerText = API_INFORMATION.version;
// Display the pastes lifetime // Display the paste lifetime
document.getElementById("lifetime").innerText = Duration.format(API_INFORMATION.pasteLifetime); document.getElementById("lifetime").innerText = Duration.format(API_INFORMATION.pasteLifetime);
} }
@ -215,7 +215,7 @@ function toggleEditMode() {
function setupKeybinds() { function setupKeybinds() {
window.addEventListener("keydown", (event) => { window.addEventListener("keydown", (event) => {
// All keybinds in the default button set include the CTRL key // All keybinds in the default button set include the CTRL key
if ((EDIT_MODE && !event.ctrlKey && event.code !== "Escape") || (!EDIT_MODE && !event.ctrlKey)) { if ((EDIT_MODE && !event.ctrlKey && !event.metaKey && event.code !== "Escape") || (!EDIT_MODE && !event.ctrlKey && !event.metaKey)) {
return; return;
} }
@ -289,7 +289,7 @@ function setupButtonFunctionality() {
return; return;
} }
// Encrypt the pastes if needed // Encrypt the paste if needed
let value = INPUT_ELEMENT.value; let value = INPUT_ELEMENT.value;
let metadata; let metadata;
let key; let key;
@ -305,20 +305,20 @@ function setupButtonFunctionality() {
key = encrypted.key; key = encrypted.key;
} }
// Try to create the pastes // Try to create the paste
const response = await API.createPaste(value, metadata); const response = await API.createPaste(value, metadata);
if (!response.ok) { if (!response.ok) {
Notifications.error("Error while creating pastes: <b>" + await response.text() + "</b>"); Notifications.error("Error while creating paste: <b>" + await response.text() + "</b>");
return; return;
} }
const data = await response.json(); const data = await response.json();
// Display the modification token if provided // Display the modification token if provided
if (data.modificationToken) { if (data.modificationToken) {
prompt("The modification token for your pastes is:", data.modificationToken); prompt("The modification token for your paste is:", data.modificationToken);
} }
// Redirect the user to his newly created pastes // Redirect the user to his newly created paste
location.replace(location.protocol + "//" + location.host + "/" + data.id + (key ? "#" + key : "")); location.replace(location.protocol + "//" + location.host + "/" + data.id + (key ? "#" + key : ""));
}); });
}); });
@ -333,10 +333,10 @@ function setupButtonFunctionality() {
return; return;
} }
// Try to delete the pastes // Try to delete the paste
const response = await API.deletePaste(PASTE_ID, modificationToken); const response = await API.deletePaste(PASTE_ID, modificationToken);
if (!response.ok) { if (!response.ok) {
Notifications.error("Error while deleting pastes: <b>" + await response.text() + "</b>"); Notifications.error("Error while deleting paste: <b>" + await response.text() + "</b>");
return; return;
} }
@ -369,17 +369,17 @@ function setupButtonFunctionality() {
return; return;
} }
// Re-encrypt the pastes data if needed // Re-encrypt the paste data if needed
let value = INPUT_ELEMENT.value; let value = INPUT_ELEMENT.value;
if (ENCRYPTION_KEY && ENCRYPTION_IV) { if (ENCRYPTION_KEY && ENCRYPTION_IV) {
const encrypted = await Encryption.encrypt(await Encryption.encryptionDataFromHex(ENCRYPTION_KEY, ENCRYPTION_IV), value); const encrypted = await Encryption.encrypt(await Encryption.encryptionDataFromHex(ENCRYPTION_KEY, ENCRYPTION_IV), value);
value = encrypted.result; value = encrypted.result;
} }
// Try to edit the pastes // Try to edit the paste
const response = await API.editPaste(PASTE_ID, modificationToken, value); const response = await API.editPaste(PASTE_ID, modificationToken, value);
if (!response.ok) { if (!response.ok) {
Notifications.error("Error while editing pastes: <b>" + await response.text() + "</b>"); Notifications.error("Error while editing paste: <b>" + await response.text() + "</b>");
return; return;
} }
@ -387,13 +387,13 @@ function setupButtonFunctionality() {
CODE = INPUT_ELEMENT.value; CODE = INPUT_ELEMENT.value;
updateCode(); updateCode();
toggleEditMode(); toggleEditMode();
Notifications.success("Successfully edited pastes."); Notifications.success("Successfully edited paste.");
}); });
BUTTON_TOGGLE_ENCRYPTION_ELEMENT.addEventListener("click", () => { BUTTON_TOGGLE_ENCRYPTION_ELEMENT.addEventListener("click", () => {
const active = BUTTON_TOGGLE_ENCRYPTION_ELEMENT.classList.toggle("active"); const active = BUTTON_TOGGLE_ENCRYPTION_ELEMENT.classList.toggle("active");
localStorage.setItem("encryption", active); localStorage.setItem("encryption", active);
Notifications.success((active ? "Enabled" : "Disabled") + " automatic pastes encryption."); Notifications.success((active ? "Enabled" : "Disabled") + " automatic paste encryption.");
}); });
BUTTON_REPORT_ELEMENT.addEventListener("click", async () => { BUTTON_REPORT_ELEMENT.addEventListener("click", async () => {
@ -403,17 +403,17 @@ function setupButtonFunctionality() {
return; return;
} }
// Try to report the pastes // Try to report the paste
const response = await API.reportPaste(PASTE_ID, reason); const response = await API.reportPaste(PASTE_ID, reason);
if (!response.ok) { if (!response.ok) {
Notifications.error("Error while reporting pastes: <b>" + await response.text() + "</b>"); Notifications.error("Error while reporting paste: <b>" + await response.text() + "</b>");
return; return;
} }
// Show the response message // Show the response message
const data = await response.json(); const data = await response.json();
if (!data.success) { if (!data.success) {
Notifications.error("Error while reporting pastes: <b>" + data.message + "</b>"); Notifications.error("Error while reporting paste: <b>" + data.message + "</b>");
return; return;
} }
Notifications.success(data.message); Notifications.success(data.message);