mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
[WEB] View large images on web (#189)
* Added selection icon to thumbnail * Added micro-interaction and video file indication * Added page to add page * Added image viewer * navigate assets * Added separate component for viewing the video file * Added FFmpeg modules * Added correct content-type header for serving image file * Added loading spinner
This commit is contained in:
parent
337db1c508
commit
c28251b8b4
15 changed files with 527 additions and 225 deletions
|
|
@ -1,13 +1,25 @@
|
|||
<script lang="ts">
|
||||
import type { ImmichAsset } from '../../models/immich-asset';
|
||||
import { AssetType, type ImmichAsset } from '../../models/immich-asset';
|
||||
import { session } from '$app/stores';
|
||||
import { onDestroy } from 'svelte';
|
||||
import { createEventDispatcher, onDestroy } from 'svelte';
|
||||
import { fade } from 'svelte/transition';
|
||||
import { serverEndpoint } from '../../constants';
|
||||
|
||||
import IntersectionObserver from '$lib/components/photos/intersection-observer.svelte';
|
||||
import CheckCircle from 'svelte-material-icons/CheckCircle.svelte';
|
||||
import PlayCircleOutline from 'svelte-material-icons/PlayCircleOutline.svelte';
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
export let asset: ImmichAsset;
|
||||
export let groupIndex: number;
|
||||
|
||||
let imageContent: string;
|
||||
let mouseOver: boolean = false;
|
||||
$: dispatch('mouseEvent', { isMouseOver: mouseOver, selectedGroupIndex: groupIndex });
|
||||
|
||||
let mouseOverIcon: boolean = false;
|
||||
let videoPlayerNode: HTMLVideoElement;
|
||||
|
||||
const loadImageData = async () => {
|
||||
if ($session.user) {
|
||||
|
|
@ -24,11 +36,72 @@
|
|||
}
|
||||
};
|
||||
|
||||
const loadVideoData = async () => {
|
||||
const videoUrl = `/asset/file?aid=${asset.deviceAssetId}&did=${asset.deviceId}`;
|
||||
if ($session.user) {
|
||||
const res = await fetch(serverEndpoint + videoUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: 'bearer ' + $session.user.accessToken,
|
||||
},
|
||||
});
|
||||
|
||||
const videoData = URL.createObjectURL(await res.blob());
|
||||
|
||||
videoPlayerNode.src = videoData;
|
||||
videoPlayerNode.load();
|
||||
videoPlayerNode.oncanplay = () => {
|
||||
console.log('Can play video');
|
||||
};
|
||||
|
||||
return videoData;
|
||||
}
|
||||
};
|
||||
const parseVideoDuration = (duration: string) => {
|
||||
const timePart = duration.split(':');
|
||||
const hours = timePart[0];
|
||||
const minutes = timePart[1];
|
||||
const seconds = timePart[2];
|
||||
|
||||
if (hours != '0') {
|
||||
return `${hours}:${minutes}`;
|
||||
} else {
|
||||
return `${minutes}:${seconds.split('.')[0]}`;
|
||||
}
|
||||
};
|
||||
|
||||
onDestroy(() => URL.revokeObjectURL(imageContent));
|
||||
</script>
|
||||
|
||||
<IntersectionObserver once={true} let:intersecting>
|
||||
<div class="h-[200px] w-[200px] bg-gray-100">
|
||||
<div
|
||||
class="h-[200px] w-[200px] bg-gray-100 relative hover:cursor-pointer"
|
||||
on:mouseenter={() => (mouseOver = true)}
|
||||
on:mouseleave={() => (mouseOver = false)}
|
||||
on:click={() => dispatch('viewAsset', { assetId: asset.id, deviceId: asset.deviceId })}
|
||||
>
|
||||
{#if mouseOver}
|
||||
<div
|
||||
in:fade={{ duration: 200 }}
|
||||
class="w-full h-full bg-gradient-to-b from-gray-800/50 via-white/0 to-white/0 absolute p-2"
|
||||
>
|
||||
<div
|
||||
on:mouseenter={() => (mouseOverIcon = true)}
|
||||
on:mouseleave={() => (mouseOverIcon = false)}
|
||||
class="inline-block"
|
||||
>
|
||||
<CheckCircle size="24" color={mouseOverIcon ? 'white' : '#d8dadb'} />
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if asset.type === AssetType.VIDEO}
|
||||
<div class="absolute right-2 top-2 text-white text-xs font-medium flex gap-1 place-items-center">
|
||||
{parseVideoDuration(asset.duration)}
|
||||
<PlayCircleOutline size="24" />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if intersecting}
|
||||
{#await loadImageData()}
|
||||
<div class="bg-immich-primary/10 h-[200px] w-[200px] flex place-items-center place-content-center">...</div>
|
||||
|
|
@ -37,10 +110,18 @@
|
|||
in:fade={{ duration: 200 }}
|
||||
src={imageData}
|
||||
alt={asset.id}
|
||||
class="object-cover h-[200px] w-[200px] transition-all duration-100"
|
||||
class="object-cover h-[200px] w-[200px] transition-all duration-100 z-0"
|
||||
loading="lazy"
|
||||
/>
|
||||
{/await}
|
||||
{/if}
|
||||
|
||||
<!-- {#if mouseOver && asset.type === AssetType.VIDEO}
|
||||
<div class="absolute w-full h-full top-0" on:mouseenter={loadVideoData}>
|
||||
<video autoplay class="border-2 h-[200px]" width="250px" bind:this={videoPlayerNode}>
|
||||
<track kind="captions" />
|
||||
</video>
|
||||
</div>
|
||||
{/if} -->
|
||||
</div>
|
||||
</IntersectionObserver>
|
||||
|
|
|
|||
62
web/src/lib/components/photos/photo_viewer.svelte
Normal file
62
web/src/lib/components/photos/photo_viewer.svelte
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<script lang="ts">
|
||||
import { session } from '$app/stores';
|
||||
import { serverEndpoint } from '$lib/constants';
|
||||
import { fade } from 'svelte/transition';
|
||||
|
||||
import type { ImmichAsset } from '$lib/models/immich-asset';
|
||||
import { createEventDispatcher, onMount } from 'svelte';
|
||||
import LoadingSpinner from '../shared/loading-spinner.svelte';
|
||||
|
||||
export let assetId: string;
|
||||
export let deviceId: string;
|
||||
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>
|
||||
|
||||
<div on:click={() => dispatch('close')} class="h-screen">
|
||||
{#if assetInfo}
|
||||
{#await loadAssetData()}
|
||||
<div class="flex place-items-center place-content-center h-full">
|
||||
<LoadingSpinner />
|
||||
</div>
|
||||
{:then assetData}
|
||||
<div class="flex place-items-center place-content-center h-full">
|
||||
<img
|
||||
in:fade={{ duration: 200 }}
|
||||
src={assetData}
|
||||
alt={assetId}
|
||||
class="object-cover h-full transition-all duration-100 z-0"
|
||||
loading="lazy"
|
||||
/>
|
||||
</div>
|
||||
{/await}
|
||||
{/if}
|
||||
</div>
|
||||
18
web/src/lib/components/shared/loading-spinner.svelte
Normal file
18
web/src/lib/components/shared/loading-spinner.svelte
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<div>
|
||||
<svg
|
||||
role="status"
|
||||
class="w-8 h-8 mr-2 text-gray-400 animate-spin dark:text-gray-600 fill-immich-primary"
|
||||
viewBox="0 0 100 101"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||
fill="currentFill"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue