From 356486bb75835ef3fc56a6b9934d8c29bdecaaa0 Mon Sep 17 00:00:00 2001 From: Alan Grainger <16197738+alangrainger@users.noreply.github.com> Date: Sat, 30 May 2026 10:36:09 +0800 Subject: [PATCH] Use album cover for og:image Co-authored-by: Pierre KELBERT --- app/src/immich.ts | 1 + app/src/render.ts | 5 +++++ app/src/types.ts | 2 ++ app/src/views/gallery.tsx | 11 +++++++---- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/immich.ts b/app/src/immich.ts index 6cf9b3b..8938944 100644 --- a/app/src/immich.ts +++ b/app/src/immich.ts @@ -240,6 +240,7 @@ class Immich { } // Replace the empty link.assets array with the array of assets from the album link.assets = album.assets + if (link.album) link.album.albumThumbnailAssetId = album.albumThumbnailAssetId } link.password = password diff --git a/app/src/render.ts b/app/src/render.ts index a2952ac..b7a0a7f 100644 --- a/app/src/render.ts +++ b/app/src/render.ts @@ -280,6 +280,10 @@ class Render { })) const downloadAllowed = canDownload(share) + // Prefer the album's owner-chosen cover for og:image; fall back to first + // item if the cover asset has been filtered out (e.g. trashed). + const coverId = share.album?.albumThumbnailAssetId + const ogImageItem = (coverId && items.find(i => i.id === coverId)) || items[0] const props: GalleryProps = { items, title: this.title(share), @@ -289,6 +293,7 @@ class Render { showDownload: downloadAllowed, showTitle: !!getConfigOption('ipp.gallery.showTitle', true), openItem, + ogImageItem, lightboxConfig: { // Show download button only if downloading is allowed AND configured. showDownload: downloadAllowed && !!getConfigOption('ipp.lightbox.showDownload', true), diff --git a/app/src/types.ts b/app/src/types.ts index 18e4a2c..389617b 100644 --- a/app/src/types.ts +++ b/app/src/types.ts @@ -42,6 +42,7 @@ export interface Asset { export interface Album { id: string; assets: Asset[]; + albumThumbnailAssetId?: string; } export interface SharedLink { @@ -57,6 +58,7 @@ export interface SharedLink { albumName?: string; order?: string; description?: string; + albumThumbnailAssetId?: string; } expiresAt: string | null; } diff --git a/app/src/views/gallery.tsx b/app/src/views/gallery.tsx index c7b5ce2..9685fa0 100644 --- a/app/src/views/gallery.tsx +++ b/app/src/views/gallery.tsx @@ -38,6 +38,7 @@ export interface GalleryProps { showDownload: boolean showTitle: boolean openItem?: number + ogImageItem?: GalleryItem lightboxConfig: LightboxConfig groupByDate: boolean } @@ -50,11 +51,13 @@ export function Gallery (props: GalleryProps) { groupByDate: props.groupByDate }) const firstItem = props.items[0] - // For videos, previewUrl points to the .mp4; use thumbnailUrl so og:image is always a still JPEG. - const ogImageAsset = firstItem - ? (firstItem.type === AssetType.video ? firstItem.thumbnailUrl : firstItem.previewUrl) + // og:image prefers the album cover (passed via props); for videos, previewUrl + // points to the .mp4, so use thumbnailUrl to keep og:image a still JPEG. + const ogItem = props.ogImageItem || firstItem + const ogImageAsset = ogItem + ? (ogItem.type === AssetType.video ? ogItem.thumbnailUrl : ogItem.previewUrl) : '' - const ogImageUrl = firstItem ? props.publicBaseUrl + ogImageAsset : '' + const ogImageUrl = ogItem ? props.publicBaseUrl + ogImageAsset : '' return (