Update client.js

This commit is contained in:
nune 2024-12-18 16:57:23 -05:00 committed by GitHub
parent 4fe9b4b341
commit 8e35036e46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,18 +1,7 @@
document.getElementById('fetchBtn').addEventListener('click', async () => { document.getElementById('fetchBtn').addEventListener('click', async () => {
const urlInput = document.getElementById('pasteUrl').value; const urlInput = document.getElementById('pasteUrl').value;
const output = document.getElementById('output');
output.textContent = 'Loading...';
try { // Perform a redirection by using the input URL directly
const response = await fetch(`/fetch-paste?url=${encodeURIComponent(urlInput)}`); const redirectUrl = `/fetch-paste?url=${encodeURIComponent(urlInput)}`;
if (!response.ok) { window.location.href = redirectUrl; // This redirects the user to the raw paste URL
const errorData = await response.json(); // Parse error JSON
throw new Error(errorData.error || 'Unknown error occurred');
}
const text = await response.text(); // Always plain text
output.textContent = text; // Display raw text
} catch (error) {
output.textContent = `Error: ${error.message}`;
}
}); });