2022-05-27 14:02:06 -05:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { session } from '$app/stores';
|
|
|
|
|
import { fade } from 'svelte/transition';
|
|
|
|
|
|
|
|
|
|
import { createEventDispatcher, onMount } from 'svelte';
|
|
|
|
|
import LoadingSpinner from '../shared/loading-spinner.svelte';
|
2022-07-10 21:41:45 -05:00
|
|
|
import { api, AssetResponseDto } from '@api';
|
2022-05-27 14:02:06 -05:00
|
|
|
|
|
|
|
|
export let assetId: string;
|
|
|
|
|
export let deviceId: string;
|
2022-06-03 11:04:30 -05:00
|
|
|
|
2022-07-10 21:41:45 -05:00
|
|
|
let assetInfo: AssetResponseDto;
|
2022-05-27 14:02:06 -05:00
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
|
if ($session.user) {
|
2022-07-10 21:41:45 -05:00
|
|
|
const { data } = await api.assetApi.getAssetById(assetId);
|
|
|
|
|
assetInfo = data;
|
2022-05-27 14:02:06 -05:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const loadAssetData = async () => {
|
|
|
|
|
if ($session.user) {
|
2022-07-10 21:41:45 -05:00
|
|
|
try {
|
|
|
|
|
const { data } = await api.assetApi.serveFile(assetInfo.deviceAssetId, deviceId, false, true, {
|
|
|
|
|
responseType: 'blob',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!(data instanceof Blob)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const assetData = URL.createObjectURL(data);
|
|
|
|
|
return assetData;
|
|
|
|
|
} catch (e) {}
|
2022-05-27 14:02:06 -05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
2022-06-03 11:04:30 -05:00
|
|
|
<div transition:fade={{ duration: 150 }} class="flex place-items-center place-content-center h-full select-none">
|
2022-05-27 14:02:06 -05:00
|
|
|
{#if assetInfo}
|
|
|
|
|
{#await loadAssetData()}
|
2022-06-03 11:04:30 -05:00
|
|
|
<LoadingSpinner />
|
2022-05-27 14:02:06 -05:00
|
|
|
{:then assetData}
|
2022-06-03 11:04:30 -05:00
|
|
|
<img
|
|
|
|
|
transition:fade={{ duration: 150 }}
|
|
|
|
|
src={assetData}
|
|
|
|
|
alt={assetId}
|
|
|
|
|
class="object-contain h-full transition-all"
|
|
|
|
|
loading="lazy"
|
|
|
|
|
/>
|
2022-05-27 14:02:06 -05:00
|
|
|
{/await}
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|