[ui] refactor blobpreview, fix model previews

This commit is contained in:
Tomáš Mládek 2022-02-03 16:39:54 +01:00
parent faed70fe03
commit ac6670ef1b
No known key found for this signature in database
GPG key ID: ED21612889E75EC5

View file

@ -8,26 +8,32 @@
$: ({ entity } = useEntity(address)); $: ({ entity } = useEntity(address));
$: mimeType = String($entity?.get("FILE_MIME")); $: mimeType = String($entity?.get("FILE_MIME"));
$: handled =
Boolean(mimeType) && $: audio = mimeType.startsWith("audio");
["audio", "video", "image", "model", "text", "application/pdf"].some( $: video = ["video", "application/x-matroska"].some((p) =>
(prefix) => mimeType.startsWith(prefix) mimeType.startsWith(p)
); );
$: image = mimeType.startsWith("image");
$: text = mimeType.startsWith("text");
$: pdf = mimeType.startsWith("pdf");
$: model = mimeType?.startsWith("model");
$: handled = audio || video || image || text || pdf || model;
let imageLoaded = null; let imageLoaded = null;
</script> </script>
{#if handled} {#if handled}
<div class="preview"> <div class="preview">
{#if mimeType?.startsWith("text")} {#if text}
<div class="text"> <div class="text">
<TextViewer {address} /> <TextViewer {address} />
</div> </div>
{/if} {/if}
{#if mimeType?.startsWith("audio")} {#if audio}
<audio controls preload="auto" src="/api/raw/{address}" /> <audio controls preload="auto" src="/api/raw/{address}" />
{/if} {/if}
{#if mimeType?.startsWith("video")} {#if video}
<!-- svelte-ignore a11y-media-has-caption --> <!-- svelte-ignore a11y-media-has-caption -->
<video <video
controls controls
@ -36,7 +42,7 @@
poster="/api/thumb/{address}" poster="/api/thumb/{address}"
/> />
{/if} {/if}
{#if mimeType?.startsWith("image")} {#if image}
<a target="_blank" href="/api/raw/{address}?inline=1"> <a target="_blank" href="/api/raw/{address}?inline=1">
{#if imageLoaded != address} {#if imageLoaded != address}
<Spinner /> <Spinner />
@ -49,13 +55,13 @@
/> />
</a> </a>
{/if} {/if}
{#if mimeType == "application/pdf"} {#if pdf}
<iframe <iframe
src="/api/raw/{address}?inline" src="/api/raw/{address}?inline"
title="PDF document of {address}" title="PDF document of {address}"
/> />
{/if} {/if}
{#if mimeType?.startsWith("model")} {#if model}
<ModelViewer src="/api/raw/{address}" /> <ModelViewer src="/api/raw/{address}" />
{/if} {/if}
</div> </div>