feat: enhance decryption process with status updates and improved user feedback

This commit is contained in:
2026-01-20 09:14:48 -05:00
parent 5410a8973a
commit 7b3af77449
+22 -3
View File
@@ -52,6 +52,7 @@
let pasteContent = ''; let pasteContent = '';
let decryptedContent: string | null = null; let decryptedContent: string | null = null;
let decryptError = ''; let decryptError = '';
let decryptStatus = '';
let contentRendered = false; let contentRendered = false;
let downloadedPaste = false; let downloadedPaste = false;
let copiedPaste = false; let copiedPaste = false;
@@ -132,6 +133,7 @@
isBinary = isBinaryData(buffer); isBinary = isBinaryData(buffer);
if (isBinary) { if (isBinary) {
contentRendered = true; contentRendered = true;
decryptStatus = '';
return; return;
} }
@@ -159,6 +161,7 @@
const wrapped = `<pre><code class="hljs">${highlighted}</code></pre>`; const wrapped = `<pre><code class="hljs">${highlighted}</code></pre>`;
pasteContent = addLineNumbers(wrapped); pasteContent = addLineNumbers(wrapped);
contentRendered = true; contentRendered = true;
decryptStatus = '';
} }
async function updatePaste(content: string | null, metadata: Paste | null) { async function updatePaste(content: string | null, metadata: Paste | null) {
@@ -278,39 +281,53 @@
try { try {
if (data?.paste && data.paste.visibility === 2) { if (data?.paste && data.paste.visibility === 2) {
contentRendered = false; contentRendered = false;
decryptStatus = 'Preparing decryption...';
const urlHash = window.location.hash.slice(1); const urlHash = window.location.hash.slice(1);
if (urlHash) { if (urlHash) {
const passwordFromUrl = atob(urlHash); const passwordFromUrl = atob(urlHash);
decryptStatus = 'Deriving key...';
decryptedContent = await decryptAES(data.content, passwordFromUrl); decryptedContent = await decryptAES(data.content, passwordFromUrl);
if (decryptedContent === null) { if (decryptedContent === null) {
decryptStatus = 'Waiting for password...';
const password = await promptUser('decrypt'); const password = await promptUser('decrypt');
if (password) { if (password) {
decryptStatus = 'Deriving key...';
decryptedContent = await decryptAES(data.content, password); decryptedContent = await decryptAES(data.content, password);
if (decryptedContent === null) { if (decryptedContent === null) {
decryptError = 'Incorrect password. Please try again.'; decryptError = 'Incorrect password. Please try again.';
decryptStatus = 'Decryption failed.';
} else { } else {
renderCode(); renderCode();
history.replaceState(null, '', window.location.pathname + window.location.search); history.replaceState(null, '', window.location.pathname + window.location.search);
} }
} else {
decryptStatus = 'Decryption canceled.';
} }
} else { } else {
renderCode(); renderCode();
} }
return; return;
} }
decryptStatus = 'Waiting for password...';
const password = await promptUser('decrypt'); const password = await promptUser('decrypt');
if (password) { if (password) {
decryptStatus = 'Deriving key...';
decryptedContent = await decryptAES(data.content, password); decryptedContent = await decryptAES(data.content, password);
if (decryptedContent === null) { if (decryptedContent === null) {
decryptError = 'Incorrect password. Please try again.'; decryptError = 'Incorrect password. Please try again.';
decryptStatus = 'Decryption failed.';
} else { } else {
renderCode(); renderCode();
} }
} else {
decryptStatus = 'Decryption canceled.';
} }
} else { } else {
decryptStatus = 'Rendering content...';
renderCode(); renderCode();
} }
} catch { } catch {
decryptStatus = 'Rendering content...';
renderCode(); renderCode();
} }
}); });
@@ -359,7 +376,7 @@
</svelte:head> </svelte:head>
<main <main
class="flex min-h-[calc(100vh-60px)] w-full flex-col items-center justify-center pt-5 pb-5 text-white" class="flex min-h-[calc(100vh-120px)] w-full flex-col items-center justify-center pt-5 pb-5 text-white"
> >
<div class="w-[95%] max-w-7xl rounded border-2 border-neutral-800 bg-neutral-900 p-4"> <div class="w-[95%] max-w-7xl rounded border-2 border-neutral-800 bg-neutral-900 p-4">
{#if data.paste} {#if data.paste}
@@ -754,9 +771,11 @@
{/if} {/if}
{:else} {:else}
<div <div
class="h-15 w-full rounded-b bg-neutral-800" class="flex h-20 w-full items-center justify-center rounded-b bg-neutral-800 text-sm text-neutral-400"
class:hidden={contentRendered && !editing} class:hidden={contentRendered && !editing}
></div> >
<span class="monospace">{decryptStatus || 'Loading...'}</span>
</div>
<code <code
class="codeblock-with-lines overflow-x-auto overflow-y-auto" class="codeblock-with-lines overflow-x-auto overflow-y-auto"
class:hidden={!contentRendered} class:hidden={!contentRendered}