mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2026-09-26 20:41:45 +00:00
fix(web): snapshot files before worker transfer (Svelte proxy not cloneable)
This commit is contained in:
@@ -1,12 +1,15 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {
|
import {
|
||||||
bytesToHex,
|
|
||||||
create as apiCreate,
|
create as apiCreate,
|
||||||
|
bytesToHex,
|
||||||
packContent,
|
packContent,
|
||||||
type FileDTO, type ServerNote
|
type FileDTO,
|
||||||
|
type NoteInput,
|
||||||
|
type ServerNote,
|
||||||
} from '@cryptgeon/shared'
|
} from '@cryptgeon/shared'
|
||||||
import { t } from 'svelte-intl-precompile'
|
import { t } from 'svelte-intl-precompile'
|
||||||
import { blur } from 'svelte/transition'
|
import { blur } from 'svelte/transition'
|
||||||
|
import { transfer } from 'comlink'
|
||||||
|
|
||||||
import { status } from '$lib/stores/status'
|
import { status } from '$lib/stores/status'
|
||||||
import { notify } from '$lib/toast'
|
import { notify } from '$lib/toast'
|
||||||
@@ -15,10 +18,12 @@
|
|||||||
import FileUpload from '$lib/ui/FileUpload.svelte'
|
import FileUpload from '$lib/ui/FileUpload.svelte'
|
||||||
import Loader from '$lib/ui/Loader.svelte'
|
import Loader from '$lib/ui/Loader.svelte'
|
||||||
import MaxSize from '$lib/ui/MaxSize.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 Result, { type NoteResult } from '$lib/ui/NoteResult.svelte'
|
||||||
|
import PastedFilesPreview from '$lib/ui/PastedFilesPreview.svelte'
|
||||||
import Switch from '$lib/ui/Switch.svelte'
|
import Switch from '$lib/ui/Switch.svelte'
|
||||||
import TextArea from '$lib/ui/TextArea.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 note: { views: number; expiration: number } = $state({ views: 1, expiration: 60 })
|
||||||
let files: FileDTO[] = $state([])
|
let files: FileDTO[] = $state([])
|
||||||
@@ -53,6 +58,8 @@
|
|||||||
if (!isFile) textContent = ''
|
if (!isFile) textContent = ''
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const worker = createWorker()
|
||||||
|
|
||||||
async function handlePaste(e: ClipboardEvent) {
|
async function handlePaste(e: ClipboardEvent) {
|
||||||
const data = e.clipboardData
|
const data = e.clipboardData
|
||||||
if (!data) return
|
if (!data) return
|
||||||
@@ -123,13 +130,25 @@
|
|||||||
throw new EmptyContentError()
|
throw new EmptyContentError()
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload = packContent(
|
const filesInput: NoteInput = {
|
||||||
isFile ? { type: 'files', files } : { type: 'text', text: textContent },
|
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
|
customPassword || undefined
|
||||||
)
|
)
|
||||||
const serverNote: ServerNote = {
|
const serverNote: ServerNote = {
|
||||||
meta: {
|
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,
|
extra: payload.extra,
|
||||||
},
|
},
|
||||||
data: payload.data,
|
data: payload.data,
|
||||||
|
|||||||
Reference in New Issue
Block a user