2023-07-28 06:29:09 +02:00
|
|
|
<script lang="ts">
|
2024-05-31 13:44:04 -04:00
|
|
|
import { getAssetOriginalUrl, getKey } from '$lib/utils';
|
|
|
|
|
import { AssetMediaSize, AssetTypeEnum, viewAsset, type AssetResponseDto } from '@immich/sdk';
|
|
|
|
|
import type { AdapterConstructor, PluginConstructor } from '@photo-sphere-viewer/core';
|
2023-07-28 06:29:09 +02:00
|
|
|
import { fade } from 'svelte/transition';
|
|
|
|
|
import LoadingSpinner from '../shared-components/loading-spinner.svelte';
|
2024-07-01 00:29:10 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
2024-04-21 12:14:54 -07:00
|
|
|
export let asset: Pick<AssetResponseDto, 'id' | 'type'>;
|
|
|
|
|
|
|
|
|
|
const photoSphereConfigs =
|
|
|
|
|
asset.type === AssetTypeEnum.Video
|
|
|
|
|
? ([
|
|
|
|
|
import('@photo-sphere-viewer/equirectangular-video-adapter').then(
|
|
|
|
|
({ EquirectangularVideoAdapter }) => EquirectangularVideoAdapter,
|
|
|
|
|
),
|
|
|
|
|
import('@photo-sphere-viewer/video-plugin').then(({ VideoPlugin }) => [VideoPlugin]),
|
|
|
|
|
true,
|
|
|
|
|
import('@photo-sphere-viewer/video-plugin/index.css'),
|
|
|
|
|
] as [PromiseLike<AdapterConstructor>, Promise<PluginConstructor[]>, true, unknown])
|
|
|
|
|
: ([undefined, [], false] as [undefined, [], false]);
|
2023-08-25 00:03:28 -04:00
|
|
|
|
2023-07-28 06:29:09 +02:00
|
|
|
const loadAssetData = async () => {
|
2024-04-21 12:14:54 -07:00
|
|
|
if (asset.type === AssetTypeEnum.Video) {
|
2024-05-31 13:44:04 -04:00
|
|
|
return { source: getAssetOriginalUrl(asset.id) };
|
2024-04-21 12:14:54 -07:00
|
|
|
}
|
2024-05-31 13:44:04 -04:00
|
|
|
const data = await viewAsset({ id: asset.id, size: AssetMediaSize.Preview, key: getKey() });
|
2024-05-06 09:20:20 -07:00
|
|
|
const url = URL.createObjectURL(data);
|
2024-04-21 12:14:54 -07:00
|
|
|
return url;
|
2023-07-28 06:29:09 +02:00
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div transition:fade={{ duration: 150 }} class="flex h-full select-none place-content-center place-items-center">
|
2024-02-12 12:31:20 -08:00
|
|
|
<!-- the photo sphere viewer is quite large, so lazy load it in parallel with loading the data -->
|
2024-04-21 12:14:54 -07:00
|
|
|
{#await Promise.all([loadAssetData(), import('./photo-sphere-viewer-adapter.svelte'), ...photoSphereConfigs])}
|
2023-07-28 06:29:09 +02:00
|
|
|
<LoadingSpinner />
|
2024-04-21 12:14:54 -07:00
|
|
|
{:then [data, module, adapter, plugins, navbar]}
|
|
|
|
|
<svelte:component this={module.default} panorama={data} plugins={plugins ?? undefined} {navbar} {adapter} />
|
2024-02-12 12:31:20 -08:00
|
|
|
{:catch}
|
2024-07-01 00:29:10 +02:00
|
|
|
{$t('errors.failed_to_load_asset')}
|
2023-07-28 06:29:09 +02:00
|
|
|
{/await}
|
|
|
|
|
</div>
|