브라우저에서 HEIF 이미지를 제대로 표현하지 못하던 버그 수정 2

This commit is contained in:
static
2025-01-06 23:50:03 +09:00
parent 71a01abf6c
commit 6c4bd590f0

View File

@@ -32,24 +32,22 @@
untrack(() => { untrack(() => {
isDownloaded = true; isDownloaded = true;
if ($info.contentType.startsWith("image")) {
contentType = "image";
} else if ($info.contentType.startsWith("video")) {
contentType = "video";
}
requestFileDownload(data.id, $info.contentIv, $info.dataKey).then(async (res) => { requestFileDownload(data.id, $info.contentIv, $info.dataKey).then(async (res) => {
content = new Blob([res], { type: $info.contentType }); content = new Blob([res], { type: $info.contentType });
if (content.type === "image/heic" || content.type === "image/heif") { if (content.type === "image/heic" || content.type === "image/heif") {
contentUrl = URL.createObjectURL( contentUrl = URL.createObjectURL(
(await heic2any({ blob: content, toType: "image/jpeg" })) as Blob, (await heic2any({ blob: content, toType: "image/jpeg" })) as Blob,
); );
} else { } else if (contentType) {
contentUrl = URL.createObjectURL(content); contentUrl = URL.createObjectURL(content);
} } else {
FileSaver.saveAs(content, $info.name);
if (content.type.startsWith("image")) {
contentType = "image";
} else if (content.type.startsWith("video")) {
contentType = "video";
}
if (!contentType) {
FileSaver.saveAs(new Blob([res], { type: $info.contentType }), $info.name);
} }
}); });
}); });
@@ -80,18 +78,16 @@
</div> </div>
{/snippet} {/snippet}
{#if contentType === "image"} {#if $info && contentType === "image"}
{#if $info && content} {#if contentUrl}
{@const src = URL.createObjectURL(new Blob([content], { type: $info.contentType }))} <img src={contentUrl} alt={$info.name} />
<img {src} alt={$info.name} />
{:else} {:else}
{@render viewerLoading("이미지를 불러오고 있어요.")} {@render viewerLoading("이미지를 불러오고 있어요.")}
{/if} {/if}
{:else if contentType === "video"} {:else if contentType === "video"}
{#if $info && content} {#if contentUrl}
{@const src = URL.createObjectURL(new Blob([content], { type: $info.contentType }))}
<!-- svelte-ignore a11y_media_has_caption --> <!-- svelte-ignore a11y_media_has_caption -->
<video {src} controls></video> <video src={contentUrl} controls></video>
{:else} {:else}
{@render viewerLoading("비디오를 불러오고 있어요.")} {@render viewerLoading("비디오를 불러오고 있어요.")}
{/if} {/if}