From b8b87877d2a3dc5ccf2e44a0bbe9b3e8be857756 Mon Sep 17 00:00:00 2001 From: static Date: Thu, 23 Jan 2025 00:32:44 +0900 Subject: [PATCH] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=EC=97=90=EC=84=9C=20=EB=B7=B0=EC=96=B4=20=EB=A1=9C?= =?UTF-8?q?=EB=94=A9=20=EB=A9=94=EC=84=B8=EC=A7=80=EB=A5=BC=20=EB=8D=94=20?= =?UTF-8?q?=EB=B9=A0=EB=A5=B4=EA=B2=8C=20=ED=91=9C=EC=8B=9C=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../(fullscreen)/file/[id]/+page.svelte | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/routes/(fullscreen)/file/[id]/+page.svelte b/src/routes/(fullscreen)/file/[id]/+page.svelte index 902d09e..b86cc52 100644 --- a/src/routes/(fullscreen)/file/[id]/+page.svelte +++ b/src/routes/(fullscreen)/file/[id]/+page.svelte @@ -42,14 +42,7 @@ let viewerType: "image" | "video" | undefined = $state(); let fileBlobUrl: string | undefined = $state(); - const updateViewer = async (info: FileInfo, buffer: ArrayBuffer) => { - const contentType = info.contentType; - if (contentType.startsWith("image")) { - viewerType = "image"; - } else if (contentType.startsWith("video")) { - viewerType = "video"; - } - + const updateViewer = async (buffer: ArrayBuffer, contentType: string) => { const fileBlob = new Blob([buffer], { type: contentType }); if (contentType === "image/heic") { const { default: heic2any } = await import("heic2any"); @@ -89,11 +82,18 @@ $effect(() => { if ($info && $info.dataKey && $info.contentIv) { + const contentType = $info.contentType; + if (contentType.startsWith("image")) { + viewerType = "image"; + } else if (contentType.startsWith("video")) { + viewerType = "video"; + } + untrack(() => { if (!downloadStatus && !isDownloadRequested) { isDownloadRequested = true; requestFileDownload(data.id, $info.contentIv!, $info.dataKey!).then(async (buffer) => { - const blob = await updateViewer($info, buffer); + const blob = await updateViewer(buffer, contentType); if (!viewerType) { FileSaver.saveAs(blob, $info.name); } @@ -105,7 +105,9 @@ $effect(() => { if ($info && $downloadStatus?.status === "decrypted") { - untrack(() => !isDownloadRequested && updateViewer($info, $downloadStatus.result!)); + untrack( + () => !isDownloadRequested && updateViewer($downloadStatus.result!, $info.contentType), + ); } });