upend/webui/src/components/display/BlobPreview.svelte

89 lines
2 KiB
Svelte
Raw Normal View History

2021-11-30 23:26:40 +01:00
<script lang="ts">
2021-12-21 20:02:47 +01:00
import { useEntity } from "../../lib/entity";
2022-01-24 18:09:07 +01:00
import Spinner from "../utils/Spinner.svelte";
import ModelViewer from "./blobs/ModelViewer.svelte";
2022-01-24 15:34:08 +01:00
import TextViewer from "./blobs/TextViewer.svelte";
2021-11-30 23:26:40 +01:00
export let address: string;
$: ({ entity } = useEntity(address));
2021-11-30 23:26:40 +01:00
$: mimeType = String($entity?.get("FILE_MIME"));
2022-01-22 18:48:38 +01:00
$: handled =
Boolean(mimeType) &&
["audio", "video", "image", "model", "text", "application/pdf"].some(
(prefix) => mimeType.startsWith(prefix)
2022-01-22 18:48:38 +01:00
);
2022-01-24 18:09:07 +01:00
let imageLoaded = null;
2021-11-30 23:26:40 +01:00
</script>
2022-01-22 18:48:38 +01:00
{#if handled}
<div class="preview">
2022-01-24 14:37:27 +01:00
{#if mimeType?.startsWith("text")}
<div class="text">
2022-01-24 15:34:08 +01:00
<TextViewer {address} />
2022-01-24 14:37:27 +01:00
</div>
{/if}
2022-01-22 18:48:38 +01:00
{#if mimeType?.startsWith("audio")}
<audio controls preload="auto" src="/api/raw/{address}" />
{/if}
{#if mimeType?.startsWith("video")}
<!-- svelte-ignore a11y-media-has-caption -->
<video
controls
preload="auto"
src="/api/raw/{address}"
poster="/api/thumb/{address}"
/>
{/if}
{#if mimeType?.startsWith("image")}
<a target="_blank" href="/api/raw/{address}">
2022-01-24 18:09:07 +01:00
{#if imageLoaded != address}
<Spinner />
{/if}
<img
src="/api/thumb/{address}"
alt={address}
on:load={() => (imageLoaded = address)}
/>
2022-01-22 18:48:38 +01:00
</a>
{/if}
{#if mimeType == "application/pdf"}
<iframe src="/api/raw/{address}?inline" title="PDF document of {address}"/>
{/if}
2022-01-22 18:48:38 +01:00
{#if mimeType?.startsWith("model")}
<ModelViewer src="/api/raw/{address}" />
{/if}
</div>
{/if}
2021-11-30 23:26:40 +01:00
<style scoped lang="scss">
.preview {
display: flex;
justify-content: center;
align-items: center;
}
audio,
2021-12-05 11:32:53 +01:00
video,
2022-01-24 14:37:27 +01:00
img,
.text {
2021-11-30 23:26:40 +01:00
width: 100%;
2021-12-05 11:32:53 +01:00
max-height: 25em;
2021-11-30 23:26:40 +01:00
}
2021-12-19 11:50:40 +01:00
iframe {
width: 100%;
min-height: 25em;
}
2022-01-24 15:34:08 +01:00
.text {
display: flex;
margin-bottom: 1rem;
2021-12-19 11:50:40 +01:00
}
2022-01-24 14:37:27 +01:00
2022-01-24 15:34:08 +01:00
video {
background: rgba(128, 128, 128, 128);
2022-01-24 14:37:27 +01:00
}
2021-11-30 23:26:40 +01:00
</style>