diff --git a/SharpbinV3.Client/src/routes/+page.svelte b/SharpbinV3.Client/src/routes/+page.svelte index c34f8d6..b3c2766 100644 --- a/SharpbinV3.Client/src/routes/+page.svelte +++ b/SharpbinV3.Client/src/routes/+page.svelte @@ -5,15 +5,22 @@ import { getToken } from '$lib/utils/auth'; import { onMount } from 'svelte'; import { fly, fade } from 'svelte/transition'; - import { encryptAES } from '$lib/utils/encryption'; - import { formatBytes, formatNumber, isBinaryData } from '$lib/utils/misc'; + import { encryptAES, estimateEncryptedSize } from '$lib/utils/encryption'; + import { + formatBytes, + formatNumber, + isBinaryData, + tooltip, + syntaxFromExtension + } from '$lib/utils/misc'; import Dropdown from '$lib/components/Dropdown.svelte'; import { SvelteURLSearchParams } from 'svelte/reactivity'; - import { FileUp, X } from '@lucide/svelte'; - import { syntaxFromExtension } from '$lib/utils/misc'; + import { FileUp, X, Eye, EyeClosed, Dices } from '@lucide/svelte'; export let data: PageData; + let textArea: HTMLTextAreaElement; + let error = ''; let title = ''; let content = ''; @@ -21,11 +28,37 @@ let expiresIn: number = 0; let selectedVisibility = data.options?.visibilities?.[0]?.value; let password = ''; + let passwordVisible = false; let anonymousUpload = false; let isDragging = false; let dragError = ''; + $: currentByteSize = + selectedVisibility === 2 + ? estimateEncryptedSize(content) + : new TextEncoder().encode(content).length; + + const MAX_HEIGHT = () => Math.floor((window.innerHeight - 120) * 0.6); + + function resize() { + if (!textArea) return; + + textArea.style.height = 'auto'; + + const h = textArea.scrollHeight; + const max = MAX_HEIGHT(); + + if (h > max) { + textArea.style.height = max + 'px'; + textArea.style.overflowY = 'auto'; + } else { + textArea.style.height = h + 'px'; + textArea.style.overflowY = 'hidden'; + } + } + onMount(() => { + resize(); const render = () => { if ( window.turnstile && @@ -98,11 +131,30 @@ } } + if (content.trim().length === 0) { + error = 'Paste content cannot be empty.'; + setTimeout(() => { + error = ''; + }, 5000); + return; + } + let body = content; if (selectedVisibility === 2) { body = await encryptAES(content, password); } + if ( + data.options?.maxPasteSize && + new TextEncoder().encode(body).length > data.options.maxPasteSize + ) { + error = `Paste exceeds the maximum size limit of ${formatBytes(data.options.maxPasteSize)}. ${selectedVisibility === 2 ? 'Encryption adds some overhead.' : ''}`; + setTimeout(() => { + error = ''; + }, 5000); + return; + } + const url = `/api/paste/create?${params.toString()}`; const options: RequestInit = { method: 'POST', @@ -165,7 +217,7 @@

Create a Paste

@@ -183,17 +235,24 @@