From fd14c7353d57029b01d5e7d5bfc6773f47142b23 Mon Sep 17 00:00:00 2001 From: nune <145225213+gigirassy@users.noreply.github.com> Date: Wed, 18 Dec 2024 17:01:02 -0500 Subject: [PATCH] Update client.js --- public/client.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/public/client.js b/public/client.js index 46ced75..82ce27f 100644 --- a/public/client.js +++ b/public/client.js @@ -1,7 +1,24 @@ -document.getElementById('fetchBtn').addEventListener('click', async () => { +document.getElementById('fetchBtn').addEventListener('click', () => { const urlInput = document.getElementById('pasteUrl').value; - - // Perform a redirection by using the input URL directly - const redirectUrl = `/fetch-paste?url=${encodeURIComponent(urlInput)}`; - window.location.href = redirectUrl; // This redirects the user to the raw paste URL + + // Extract the Paste ID from the provided Pastebin URL + const pasteId = getPasteId(urlInput); + + if (pasteId) { + // Redirect to the raw paste route on your server + window.location.href = `http://localhost:3000/${pasteId}`; + } else { + alert('Please enter a valid Pastebin URL.'); + } }); + +function getPasteId(url) { + // Check if the URL is a valid Pastebin URL and extract the Paste ID + const regex = /pastebin\.com\/(?:raw\/)?([a-zA-Z0-9]+)/; + const match = url.match(regex); + + if (match) { + return match[1]; // Return the Paste ID + } + return null; // Invalid Pastebin URL +}