diff --git a/webui/src/components/display/BlobPreview.svelte b/webui/src/components/display/BlobPreview.svelte index 110def4..ba4bfb7 100644 --- a/webui/src/components/display/BlobPreview.svelte +++ b/webui/src/components/display/BlobPreview.svelte @@ -6,43 +6,26 @@ import VideoViewer from "./blobs/VideoViewer.svelte"; import HashBadge from "./HashBadge.svelte"; import { API_URL } from "../../lib/api"; - import { GROUP_TYPE_ADDR } from "upend/constants"; import { createEventDispatcher } from "svelte"; + import { getTypes } from "../../util/mediatypes"; const dispatch = createEventDispatcher(); export let address: string; export let recurse = 3; $: ({ 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"); - $: model = - mimeType?.startsWith("model") || - $entity?.identify().some((l) => l.endsWith(".stl")); - $: web = $entityInfo?.t == "Url"; - $: fragment = Boolean($entity?.get("ANNOTATES")); - - $: group = $entity?.get("IS") == GROUP_TYPE_ADDR; + $: types = getTypes($entity, $entityInfo); $: handled = !$entity || - audio || - video || - image || - text || - model || - web || - fragment || - (group && recurse > 0); + types.audio || + types.video || + types.image || + types.text || + types.model || + types.web || + types.fragment || + (types.group && recurse > 0); $: dispatch("handled", handled); @@ -80,7 +63,7 @@
{#if handled} - {#if group} + {#if types.group} - {:else if model} + {:else if types.model} - {:else if web} + {:else if types.web} {#if imageLoaded != address} {/if} @@ -106,11 +89,11 @@ on:load={() => (imageLoaded = address)} on:error={() => (handled = false)} /> - {:else if fragment} + {:else if types.fragment} - {:else if video} + {:else if types.video} - {:else if audio} + {:else if types.audio}
{#if handled && imageLoaded != address}
@@ -137,7 +120,7 @@
{/if} Thumbnail for {address}... 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")); + $: types = getTypes($entity, $entityInfo); $: handled = - audio || video || image || text || pdf || model || web || fragment; + types.audio || + types.video || + types.image || + types.text || + types.pdf || + types.model || + types.web || + types.fragment; $: dispatch("handled", handled); @@ -47,30 +39,30 @@ {#if handled}
- {#if text} + {#if types.text}
{/if} - {#if audio} + {#if types.audio} {/if} - {#if video} + {#if types.video} {/if} - {#if image} + {#if types.image} {/if} - {#if pdf} + {#if types.pdf}