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 15:34:08 +01:00
|
|
|
import IconButton from "../utils/IconButton.svelte";
|
2022-01-24 14:37:27 +01:00
|
|
|
import Spinner from "../utils/Spinner.svelte";
|
2022-01-03 10:26:01 +01:00
|
|
|
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;
|
|
|
|
|
2021-12-19 13:54:16 +01:00
|
|
|
$: ({ entity } = useEntity(address));
|
2021-11-30 23:26:40 +01:00
|
|
|
|
2021-12-19 13:54:16 +01:00
|
|
|
$: mimeType = String($entity?.get("FILE_MIME"));
|
2022-01-22 18:48:38 +01:00
|
|
|
$: handled =
|
|
|
|
Boolean(mimeType) &&
|
2022-01-24 14:37:27 +01:00
|
|
|
["audio", "video", "image", "model", "text"].some((prefix) =>
|
2022-01-22 18:48:38 +01:00
|
|
|
mimeType.startsWith(prefix)
|
|
|
|
);
|
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}">
|
|
|
|
<img src="/api/raw/{address}" alt={address} />
|
|
|
|
</a>
|
|
|
|
{/if}
|
|
|
|
{#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
|
|
|
|
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>
|