123 lines
2.9 KiB
Svelte
123 lines
2.9 KiB
Svelte
<script lang="ts">
|
|
import { useEntity } from "../../lib/entity";
|
|
import Spinner from "../utils/Spinner.svelte";
|
|
import AudioViewer from "./blobs/AudioViewer.svelte";
|
|
import FragmentViewer from "./blobs/FragmentViewer.svelte";
|
|
import ImageViewer from "./blobs/ImageViewer.svelte";
|
|
import ModelViewer from "./blobs/ModelViewer.svelte";
|
|
import TextViewer from "./blobs/TextViewer.svelte";
|
|
import VideoViewer from "./blobs/VideoViewer.svelte";
|
|
import UpLink from "./UpLink.svelte";
|
|
|
|
export let address: string;
|
|
export let editable: boolean;
|
|
export let detail: boolean;
|
|
|
|
export let handled = false;
|
|
|
|
$: ({ entity, entityInfo } = useEntity(address));
|
|
|
|
$: mimeType = String($entity?.get("FILE_MIME"));
|
|
|
|
$: audio =
|
|
["audio", "application/x-riff"].some((p) => mimeType.startsWith(p)) &&
|
|
!video;
|
|
$: video =
|
|
["video", "application/x-matroska"].some((p) => mimeType.startsWith(p)) ||
|
|
$entity?.identify().some((l) => l.endsWith(".avi"));
|
|
$: image = mimeType.startsWith("image");
|
|
$: text = mimeType.startsWith("text");
|
|
$: pdf = mimeType.startsWith("application/pdf");
|
|
$: model =
|
|
mimeType?.startsWith("model") ||
|
|
$entity?.identify().some((l) => l.endsWith(".stl"));
|
|
$: web = $entityInfo?.t == "Url";
|
|
$: fragment = Boolean($entity?.get("ANNOTATES"));
|
|
|
|
$: handled =
|
|
audio || video || image || text || pdf || model || web || fragment;
|
|
|
|
let imageLoaded = null;
|
|
</script>
|
|
|
|
{#if handled}
|
|
<div class="preview" class:detail>
|
|
{#if text}
|
|
<div class="text">
|
|
<TextViewer {address} />
|
|
</div>
|
|
{/if}
|
|
{#if audio}
|
|
<AudioViewer {address} {detail} {editable} />
|
|
{/if}
|
|
{#if video}
|
|
<VideoViewer detail {address} />
|
|
{/if}
|
|
{#if image}
|
|
<ImageViewer {address} {editable} {detail} />
|
|
{/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}
|
|
{#if fragment}
|
|
<UpLink passthrough to={{ entity: String($entity.get("ANNOTATES")) }}>
|
|
<FragmentViewer {address} {detail} />
|
|
</UpLink>
|
|
{/if}
|
|
</div>
|
|
{/if}
|
|
|
|
<style scoped lang="scss">
|
|
.preview {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
flex-direction: column;
|
|
min-height: 33vh;
|
|
max-height: 50vh;
|
|
|
|
&.detail {
|
|
max-height: 100%;
|
|
flex-grow: 1;
|
|
// min-height: 0;
|
|
}
|
|
}
|
|
|
|
img,
|
|
.text {
|
|
width: 100%;
|
|
max-height: 100%;
|
|
}
|
|
|
|
iframe {
|
|
width: 99%;
|
|
flex-grow: 1;
|
|
}
|
|
|
|
.text {
|
|
display: flex;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
img {
|
|
object-fit: contain;
|
|
}
|
|
</style>
|