2022-05-27 14:02:06 -05:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { session } from '$app/stores';
|
|
|
|
|
import { serverEndpoint } from '$lib/constants';
|
|
|
|
|
import { fade } from 'svelte/transition';
|
|
|
|
|
|
2022-06-03 11:04:30 -05:00
|
|
|
import type { ImmichAsset, ImmichExif } from '$lib/models/immich-asset';
|
2022-05-27 14:02:06 -05:00
|
|
|
import { createEventDispatcher, onMount } from 'svelte';
|
|
|
|
|
import LoadingSpinner from '../shared/loading-spinner.svelte';
|
|
|
|
|
|
|
|
|
|
export let assetId: string;
|
|
|
|
|
export let deviceId: string;
|
2022-06-03 11:04:30 -05:00
|
|
|
|
2022-05-27 14:02:06 -05:00
|
|
|
let assetInfo: ImmichAsset;
|
|
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
|
if ($session.user) {
|
|
|
|
|
const res = await fetch(serverEndpoint + '/asset/assetById/' + assetId, {
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: 'bearer ' + $session.user.accessToken,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
assetInfo = await res.json();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const loadAssetData = async () => {
|
|
|
|
|
const assetUrl = `/asset/file?aid=${assetInfo.deviceAssetId}&did=${deviceId}&isWeb=true`;
|
|
|
|
|
if ($session.user) {
|
|
|
|
|
const res = await fetch(serverEndpoint + assetUrl, {
|
|
|
|
|
method: 'GET',
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: 'bearer ' + $session.user.accessToken,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const assetData = URL.createObjectURL(await res.blob());
|
|
|
|
|
|
|
|
|
|
return assetData;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</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>
|