128 lines
2.9 KiB
Svelte
128 lines
2.9 KiB
Svelte
<script lang="ts">
|
|
import { useEntity } from "../../lib/entity";
|
|
import Spinner from "../utils/Spinner.svelte";
|
|
import ImageViewer from "./blobs/ImageViewer.svelte";
|
|
import ModelViewer from "./blobs/ModelViewer.svelte";
|
|
import TextViewer from "./blobs/TextViewer.svelte";
|
|
export let address: string;
|
|
|
|
$: ({ entity, entityInfo } = useEntity(address));
|
|
|
|
$: mimeType = String($entity?.get("FILE_MIME"));
|
|
|
|
$: audio = ["audio", "application/x-riff"].some((p) =>
|
|
mimeType.startsWith(p)
|
|
);
|
|
$: video = ["video", "application/x-matroska"].some((p) =>
|
|
mimeType.startsWith(p)
|
|
);
|
|
$: image = mimeType.startsWith("image");
|
|
$: text = mimeType.startsWith("text");
|
|
$: pdf = mimeType.startsWith("application/pdf");
|
|
$: model = mimeType?.startsWith("model");
|
|
$: web = $entityInfo?.t == "Url";
|
|
|
|
$: handled = audio || video || image || text || pdf || model || web;
|
|
|
|
let imageLoaded = null;
|
|
</script>
|
|
|
|
{#if handled}
|
|
<div class="preview">
|
|
{#if text}
|
|
<div class="text">
|
|
<TextViewer {address} />
|
|
</div>
|
|
{/if}
|
|
{#if audio}
|
|
{#if imageLoaded != address}
|
|
<Spinner />
|
|
{/if}
|
|
<img
|
|
src="api/thumb/{address}"
|
|
alt={address}
|
|
on:load={() => (imageLoaded = address)}
|
|
on:error={() => (imageLoaded = address)}
|
|
/>
|
|
<audio controls preload="auto" src="api/raw/{address}" />
|
|
{/if}
|
|
{#if video}
|
|
{#if imageLoaded != address}
|
|
<Spinner />
|
|
|
|
<img
|
|
src="api/thumb/{address}"
|
|
alt={address}
|
|
on:load={() => (imageLoaded = address)}
|
|
on:error={() => (imageLoaded = address)}
|
|
/>
|
|
{:else}
|
|
<!-- svelte-ignore a11y-media-has-caption -->
|
|
<video
|
|
controls
|
|
preload="auto"
|
|
src="api/raw/{address}"
|
|
poster="api/thumb/{address}"
|
|
/>
|
|
{/if}
|
|
{/if}
|
|
{#if image}
|
|
<div class="image">
|
|
<ImageViewer {address} />
|
|
</div>
|
|
{/if}
|
|
{#if pdf}
|
|
<iframe
|
|
src="api/raw/{address}?inline"
|
|
title="PDF document of {address}"
|
|
/>
|
|
{/if}
|
|
{#if model}
|
|
<ModelViewer src="api/raw/{address}" />
|
|
{/if}
|
|
{#if web}
|
|
{#if imageLoaded != address}
|
|
<Spinner />
|
|
{/if}
|
|
<img
|
|
src={String($entity?.get("OG_IMAGE"))}
|
|
alt="OpenGraph image for {$entityInfo?.t == 'Url' && $entityInfo?.c}"
|
|
on:load={() => (imageLoaded = address)}
|
|
on:error={() => (handled = false)}
|
|
/>
|
|
{/if}
|
|
</div>
|
|
{/if}
|
|
|
|
<style scoped lang="scss">
|
|
.preview {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
flex-direction: column;
|
|
}
|
|
|
|
audio,
|
|
video,
|
|
img,
|
|
.image,
|
|
.text {
|
|
width: 100%;
|
|
height: var(--preview-height, 25em);
|
|
}
|
|
|
|
iframe {
|
|
width: 100%;
|
|
min-height: var(--preview-height, 25em);
|
|
}
|
|
|
|
.text {
|
|
display: flex;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
video {
|
|
background: rgba(128, 128, 128, 128);
|
|
}
|
|
</style>
|