diff --git a/SharpbinV3.Client/src/lib/utils/misc.ts b/SharpbinV3.Client/src/lib/utils/misc.ts index 3dce5df..f3d0a51 100644 --- a/SharpbinV3.Client/src/lib/utils/misc.ts +++ b/SharpbinV3.Client/src/lib/utils/misc.ts @@ -24,6 +24,19 @@ export function extractDateFromUUIDv7(uuid?: string): Date | null { return new Date(parseInt(timestampHex, 16)); } +export function isBinaryData(buffer: ArrayBuffer | Uint8Array): boolean { + const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer); + + if (bytes.includes(0)) return true; + + try { + new TextDecoder('utf-8', { fatal: true }).decode(bytes); + return false; + } catch { + return true; + } +} + export function extractError(resData: unknown): string | null { if (!resData || typeof resData !== 'object') return null; diff --git a/SharpbinV3.Client/src/routes/+page.svelte b/SharpbinV3.Client/src/routes/+page.svelte index 79dd881..3d09a29 100644 --- a/SharpbinV3.Client/src/routes/+page.svelte +++ b/SharpbinV3.Client/src/routes/+page.svelte @@ -4,11 +4,12 @@ import { user } from '$lib/stores/user'; import { getToken } from '$lib/utils/auth'; import { onMount } from 'svelte'; - import { fly } from 'svelte/transition'; + import { fly, fade } from 'svelte/transition'; import { encryptAES } from '$lib/utils/encryption'; - import { formatBytes, formatNumber } from '$lib/utils/misc'; + import { formatBytes, formatNumber, isBinaryData } from '$lib/utils/misc'; import Dropdown from '$lib/components/Dropdown.svelte'; import { SvelteURLSearchParams } from 'svelte/reactivity'; + import { FileUp, X } from '@lucide/svelte'; export let data: PageData; @@ -20,6 +21,8 @@ let selectedVisibility = data.options?.visibilities?.[0]?.value; let password = ''; let anonymousUpload = false; + let isDragging = false; + let dragError = ''; onMount(() => { const render = () => { @@ -98,12 +101,14 @@ if (selectedVisibility === 2) { body = await encryptAES(content, password); } + const url = `/api/paste/create?${params.toString()}`; const options: RequestInit = { method: 'POST', headers: { 'Content-Type': 'text/plain' }, body }; + if ($user && !anonymousUpload) { const token = getToken(); if (token) { @@ -142,7 +147,7 @@ error = resData.message || 'Registration failed. Please try again.'; } } - setInterval(() => { + setTimeout(() => { error = ''; }, 5000); } @@ -173,24 +178,88 @@ bind:value={title} maxlength={data.options?.maxTitleLength ?? 500} /> -