fix(journey): serve a medium preview to large photo tiles

Entry cards and the entry photo grid loaded the provider thumbnail (about
250 px for Immich) and drew it blurry. Photos now have a medium "preview"
rendition: Immich's preview, Synology's xl and a local photo's 800 px
thumbnail. GET /api/photos/:id/preview serves it behind the same access
check, and both share link photo routes now hand a preview on instead of
reading every size but thumbnail as the original. The entry grid, the
entry covers, the phone feed cards and the share page's large tiles ask
for it; small tiles keep the thumbnail.

The Synology picker named no size and got the 240 px rendition; its
tiles now ask for the medium one.
This commit is contained in:
Maurice
2026-11-30 14:28:29 +01:00
parent 3a300a3996
commit 555027f10f
28 changed files with 278 additions and 54 deletions
@@ -98,7 +98,7 @@ describe('the journal entries card', () => {
expect(screen.getByText('4 photos')).toBeInTheDocument();
expect(screen.getByText('Opens with a video')).toBeInTheDocument();
expect(screen.getByText('Berlin 2026')).toBeInTheDocument();
expect(container.querySelector('img')).toHaveAttribute('src', '/api/photos/7/thumbnail');
expect(container.querySelector('img')).toHaveAttribute('src', '/api/photos/7/preview');
});
it('FE-AI-JOURNEY-002: an entry without a photo takes the width, and a known mood and weather are named', () => {
@@ -236,7 +236,7 @@ describe('a change row of a journal entry', () => {
expect(screen.getByText('Tue, Oct 21')).toBeInTheDocument();
expect(screen.getByText('Museum Island')).toBeInTheDocument();
expect(screen.queryByText('Not a fact')).toBeNull();
expect(document.querySelector('img')).toHaveAttribute('src', '/api/photos/7/thumbnail');
expect(document.querySelector('img')).toHaveAttribute('src', '/api/photos/7/preview');
first.unmount();
const second = inView(<AssistantChangeCard items={[item('applied', held)]} />, { onOpen });
@@ -59,7 +59,7 @@ describe('EntryCard', () => {
it('FE-JRN-CARD-002: renders the photo hero with the title overlaid', () => {
const { container } = mountCard(buildEntry({ photos: [buildPhoto(100)] }))
const img = container.querySelector('img[src="/api/photos/100/thumbnail"]')
const img = container.querySelector('img[src="/api/photos/100/preview"]')
expect(img).toBeInTheDocument()
expect(screen.getByRole('heading', { name: 'Arrived in Rome' })).toBeInTheDocument()
})
@@ -69,7 +69,7 @@ describe('EntryCard', () => {
const photos = [buildPhoto(100), buildPhoto(101)]
const { container, onPhotoClick } = mountCard(buildEntry({ photos }))
await user.click(container.querySelector('img[src="/api/photos/101/thumbnail"]') as HTMLElement)
await user.click(container.querySelector('img[src="/api/photos/101/preview"]') as HTMLElement)
expect(onPhotoClick).toHaveBeenCalledWith(photos, 1)
})
@@ -17,16 +17,16 @@ function buildPhoto(overrides: Partial<JourneyPhoto> = {}): JourneyPhoto {
}
describe('PhotoImg', () => {
it('asks for the thumbnail of a photo', () => {
it('asks for the preview of a photo, the size a large tile needs (#2874)', () => {
const { container } = render(<PhotoImg photo={buildPhoto()} />)
expect(container.querySelector('img')).toHaveAttribute('src', '/api/photos/515/thumbnail')
expect(container.querySelector('img')).toHaveAttribute('src', '/api/photos/515/preview')
})
it('shows the poster of a clip behind the play badge', () => {
const { container } = render(<PhotoImg photo={buildPhoto({ media_type: 'video', thumbnail_path: 'journey/poster.jpg' })} />)
expect(container.querySelector('img')).toHaveAttribute('src', '/api/photos/515/thumbnail')
expect(container.querySelector('img')).toHaveAttribute('src', '/api/photos/515/preview')
expect(container.querySelector('svg')).not.toBeNull()
})
@@ -43,6 +43,6 @@ describe('PhotoImg', () => {
it('still asks the server for a provider clip, which serves its own poster', () => {
const { container } = render(<PhotoImg photo={buildPhoto({ media_type: 'video', provider: 'immich', thumbnail_path: null })} />)
expect(container.querySelector('img')).toHaveAttribute('src', '/api/photos/515/thumbnail')
expect(container.querySelector('img')).toHaveAttribute('src', '/api/photos/515/preview')
})
})
@@ -3,7 +3,8 @@ import type { JourneyPhoto } from '../../store/journeyStore'
import { photoUrl, posterlessVideo } from '../../pages/journeyDetail/JourneyDetailPage.helpers'
export function PhotoImg({ photo, className, style }: { photo: JourneyPhoto; className?: string; style?: React.CSSProperties }) {
const src = photoUrl(photo, 'thumbnail')
// Every tile of the entry grid is a large one (#2874), so it asks for the preview.
const src = photoUrl(photo, 'preview')
const isVideo = photo.media_type === 'video'
return (
@@ -19,6 +19,7 @@ import {
import type { JourneyEntry, JourneyTrip } from '../../store/journeyStore';
import { DatePicker } from './JourneyDetailPageDatePicker';
import { ScrollTrigger } from './JourneyDetailPageScrollTrigger';
import { providerAssetUrl } from './providerAssetUrl';
export type ProviderPhotoGroup = { assetIds: string[]; passphrase?: string; mediaTypes?: string[] };
@@ -691,13 +692,13 @@ export function ProviderPicker({
}`}
>
<img
src={`/api/integrations/memories/${provider}/assets/0/${asset.id}/${userId}/thumbnail${selectedAlbumPassphrase ? `?passphrase=${encodeURIComponent(selectedAlbumPassphrase)}` : ''}`}
src={providerAssetUrl(provider, asset.id, userId, 'thumbnail', selectedAlbumPassphrase)}
alt=""
className="h-full w-full object-cover"
loading="lazy"
onError={(e) => {
const img = e.currentTarget;
const original = `/api/integrations/memories/${provider}/assets/0/${asset.id}/${userId}/original${selectedAlbumPassphrase ? `?passphrase=${encodeURIComponent(selectedAlbumPassphrase)}` : ''}`;
const original = providerAssetUrl(provider, asset.id, userId, 'original', selectedAlbumPassphrase);
if (!img.src.includes('/original')) img.src = original;
}}
/>
@@ -24,7 +24,7 @@ describe('JourneyEntryCover', () => {
// empty alt and no img role.
const { container } = render(<JourneyEntryCover entry={buildEntry()} dayColor="#6366f1" isActive={false} onClick={() => {}} />)
expect(container.querySelector('img')).toHaveAttribute('src', '/api/photos/7/thumbnail')
expect(container.querySelector('img')).toHaveAttribute('src', '/api/photos/7/preview')
expect(screen.getByText('Mercado da Ribeira')).toBeInTheDocument()
expect(screen.getByText('Lisbon, Portugal')).toBeInTheDocument()
})
@@ -35,7 +35,7 @@ describe('JourneyEntryCover', () => {
const { container } = render(<JourneyEntryCover entry={buildEntry({ photos: [] })} dayColor="#6366f1" isActive={false} onClick={() => {}} />)
// The country's flag is an <img> of its own, so the photo is queried by source.
expect(container.querySelector('img[src*="/thumbnail"]')).toBeNull()
expect(container.querySelector('img[src*="/api/photos/"]')).toBeNull()
expect(screen.getByText('Mercado da Ribeira')).toBeInTheDocument()
})
@@ -121,7 +121,7 @@ describe('JourneyEntryCover', () => {
const entry = buildEntry({ photos: [{ photo_id: 7, media_type: 'video', provider: 'local', thumbnail_path: null }] })
const { container } = render(<JourneyEntryCover entry={entry} dayColor="#6366f1" isActive={false} onClick={() => {}} />)
expect(container.querySelector('img[src*="/thumbnail"]')).toBeNull()
expect(container.querySelector('img[src*="/api/photos/"]')).toBeNull()
expect(container.querySelector('svg.lucide-play')).toBeInTheDocument()
expect(container.querySelector('svg.lucide-map-pin')).toBeNull()
})
@@ -130,7 +130,7 @@ describe('JourneyEntryCover', () => {
const entry = buildEntry({ photos: [{ photo_id: 7, media_type: 'video', provider: 'local', thumbnail_path: 'journey/poster.jpg' }] })
const { container } = render(<JourneyEntryCover entry={entry} dayColor="#6366f1" isActive={false} onClick={() => {}} />)
expect(container.querySelector('img')).toHaveAttribute('src', '/api/photos/7/thumbnail')
expect(container.querySelector('img')).toHaveAttribute('src', '/api/photos/7/preview')
expect(container.querySelector('svg.lucide-play')).toBeNull()
})
@@ -91,7 +91,8 @@ export default function JourneyEntryCover({
// A clip without a poster has no picture to fill the card with; its thumbnail
// route 404s and an <img> pointed at it would draw the broken glyph (#2341).
const posterless = first != null && posterlessVideo(first)
const src = photoId == null || posterless ? null : photoUrlFor ? photoUrlFor(photoId) : `/api/photos/${photoId}/thumbnail`
// The card fills its tile with the photo, too large for the thumbnail (#2874).
const src = photoId == null || posterless ? null : photoUrlFor ? photoUrlFor(photoId) : `/api/photos/${photoId}/preview`
const title = cardTitle(entry, t)
const place = cardPlace(entry)
@@ -0,0 +1,29 @@
// FE-JRN-ASSETURL-001 to FE-JRN-ASSETURL-003
import { describe, expect, it } from 'vitest';
import { providerAssetUrl } from './providerAssetUrl';
describe('providerAssetUrl', () => {
it('FE-JRN-ASSETURL-001: a Synology thumbnail names the medium size, so the picker tile is sharp', () => {
expect(providerAssetUrl('synologyphotos', '101_ck', 7, 'thumbnail')).toBe(
'/api/integrations/memories/synologyphotos/assets/0/101_ck/7/thumbnail?size=m'
);
});
it('FE-JRN-ASSETURL-002: an Immich thumbnail and any original name no size', () => {
expect(providerAssetUrl('immich', 'a1', 7, 'thumbnail')).toBe(
'/api/integrations/memories/immich/assets/0/a1/7/thumbnail'
);
expect(providerAssetUrl('synologyphotos', '101_ck', 7, 'original')).toBe(
'/api/integrations/memories/synologyphotos/assets/0/101_ck/7/original'
);
});
it('FE-JRN-ASSETURL-003: a shared album passes its passphrase along, encoded', () => {
const src = providerAssetUrl('synologyphotos', '101_ck', 7, 'thumbnail', 'a b&c');
expect(src).toContain('passphrase=a%20b%26c');
const url = new URL(src, 'http://x');
expect(url.searchParams.get('passphrase')).toBe('a b&c');
expect(url.searchParams.get('size')).toBe('m');
expect(providerAssetUrl('immich', 'a1', 7, 'original', null)).not.toContain('?');
});
});
@@ -0,0 +1,21 @@
/**
* The address of one asset of a connected photo library, as the picker shows it.
*
* Synology answers its smallest rendition (240 px) when the request names no
* size, and the picker's tiles drew blurry with it (#2874), so a thumbnail asks
* for 'm'. Immich has a single thumbnail size on this route and takes none. A
* shared album's passphrase goes along, as the server needs it to reach the asset.
*/
export function providerAssetUrl(
provider: string,
assetId: string,
userId: number,
kind: 'thumbnail' | 'original',
passphrase?: string | null
): string {
const query: string[] = [];
if (provider === 'synologyphotos' && kind === 'thumbnail') query.push('size=m');
if (passphrase) query.push(`passphrase=${encodeURIComponent(passphrase)}`);
const search = query.length > 0 ? `?${query.join('&')}` : '';
return `/api/integrations/memories/${provider}/assets/0/${assetId}/${userId}/${kind}${search}`;
}