fix(web): snapshot files before worker transfer (Svelte proxy not cloneable)

This commit is contained in:
2026-09-13 21:17:24 +02:00
parent 0d597edfee
commit a57ead61b9
+25 -6
View File
@@ -1,12 +1,15 @@
<script lang="ts">
import {
bytesToHex,
create as apiCreate,
bytesToHex,
packContent,
type FileDTO, type ServerNote
type FileDTO,
type NoteInput,
type ServerNote,
} from '@cryptgeon/shared'
import { t } from 'svelte-intl-precompile'
import { blur } from 'svelte/transition'
import { transfer } from 'comlink'
import { status } from '$lib/stores/status'
import { notify } from '$lib/toast'
@@ -15,10 +18,12 @@
import FileUpload from '$lib/ui/FileUpload.svelte'
import Loader from '$lib/ui/Loader.svelte'
import MaxSize from '$lib/ui/MaxSize.svelte'
import PastedFilesPreview from '$lib/ui/PastedFilesPreview.svelte'
import Result, { type NoteResult } from '$lib/ui/NoteResult.svelte'
import PastedFilesPreview from '$lib/ui/PastedFilesPreview.svelte'
import Switch from '$lib/ui/Switch.svelte'
import TextArea from '$lib/ui/TextArea.svelte'
import { createWorker } from '$lib/worker'
import { onMount } from 'svelte'
let note: { views: number; expiration: number } = $state({ views: 1, expiration: 60 })
let files: FileDTO[] = $state([])
@@ -53,6 +58,8 @@
if (!isFile) textContent = ''
})
const worker = createWorker()
async function handlePaste(e: ClipboardEvent) {
const data = e.clipboardData
if (!data) return
@@ -123,13 +130,25 @@
throw new EmptyContentError()
}
const payload = packContent(
isFile ? { type: 'files', files } : { type: 'text', text: textContent },
const filesInput: NoteInput = {
type: 'files',
files: $state.snapshot(files),
}
const payload = await worker.pack(
isFile
? transfer(
filesInput,
filesInput.files.map((f) => f.data.buffer)
)
: { type: 'text', text: textContent },
customPassword || undefined
)
const serverNote: ServerNote = {
meta: {
...(timeExpiration ? { expiration: parseInt(note.expiration as any) } : { views: parseInt(note.views as any) }),
...(timeExpiration
? { expiration: parseInt(note.expiration as any) }
: { views: parseInt(note.views as any) }),
extra: payload.extra,
},
data: payload.data,