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}`;
}
@@ -170,7 +170,7 @@ function FeedPhoto({ entry }: { entry: JourneyEntry }) {
</span>
) : (
<img
src={`/api/photos/${photoId}/thumbnail`}
src={`/api/photos/${photoId}/preview`}
alt=""
loading="lazy"
className="absolute inset-0 h-full w-full object-cover"
+7 -7
View File
@@ -168,7 +168,7 @@ describe('JourneyDetailPage', () => {
// img with alt="" is presentational (no 'img' role), so query the DOM directly
const images = document.querySelectorAll('img');
const srcs = Array.from(images).map((img) => img.getAttribute('src'));
expect(srcs).toContain('/api/photos/100/thumbnail');
expect(srcs).toContain('/api/photos/100/preview');
});
});
@@ -413,7 +413,7 @@ describe('JourneyDetailPage', () => {
await renderAndWait();
const imgs = document.querySelectorAll('img');
const photoSrcs = Array.from(imgs).map((img) => img.getAttribute('src'));
expect(photoSrcs).toContain('/api/photos/100/thumbnail');
expect(photoSrcs).toContain('/api/photos/100/preview');
});
});
@@ -452,9 +452,9 @@ describe('JourneyDetailPage', () => {
const imgs = document.querySelectorAll('img');
const photoSrcs = Array.from(imgs).map((img) => img.getAttribute('src'));
expect(photoSrcs).toContain('/api/photos/100/thumbnail');
expect(photoSrcs).toContain('/api/photos/101/thumbnail');
expect(photoSrcs).toContain('/api/photos/102/thumbnail');
expect(photoSrcs).toContain('/api/photos/100/preview');
expect(photoSrcs).toContain('/api/photos/101/preview');
expect(photoSrcs).toContain('/api/photos/102/preview');
});
});
@@ -2576,8 +2576,8 @@ describe('JourneyDetailPage', () => {
// Both photos render in the grid
const imgs = document.querySelectorAll('img');
const srcs = Array.from(imgs).map(img => img.getAttribute('src'));
expect(srcs).toContain('/api/photos/100/thumbnail');
expect(srcs).toContain('/api/photos/101/thumbnail');
expect(srcs).toContain('/api/photos/100/preview');
expect(srcs).toContain('/api/photos/101/preview');
});
});
+10 -6
View File
@@ -69,7 +69,11 @@ const WEATHER_CONFIG: Record<string, { icon: typeof Sun; label: string }> = {
cold: { icon: Snowflake, label: 'Cold' },
};
function photoUrl(p: { photo_id: number }, shareToken: string, kind: 'thumbnail' | 'original' = 'original'): string {
function photoUrl(
p: { photo_id: number },
shareToken: string,
kind: 'thumbnail' | 'preview' | 'original' = 'original'
): string {
return `/api/public/journey/${shareToken}/photos/${p.photo_id}/${kind}`;
}
@@ -336,7 +340,7 @@ export default function JourneyPublicPage() {
>
{!posterlessVideo(p) && (
<img
src={photoUrl(p, token!, 'thumbnail')}
src={photoUrl(p, token!, 'preview')}
alt=""
className={`h-full w-full ${p.media_type === 'video' ? 'object-contain' : 'object-cover'
}`}
@@ -366,7 +370,7 @@ export default function JourneyPublicPage() {
<ClipTile />
) : (
<img
src={photoUrl(photos[0], token!, 'thumbnail')}
src={photoUrl(photos[0], token!, 'preview')}
alt=""
className={`h-full w-full ${photos[0].media_type === 'video' ? 'object-contain bg-black' : 'object-cover'
}`}
@@ -383,7 +387,7 @@ export default function JourneyPublicPage() {
<ClipTile />
) : (
<img
src={photoUrl(photos[1], token!, 'thumbnail')}
src={photoUrl(photos[1], token!, 'preview')}
alt=""
className={`h-full w-full ${photos[1].media_type === 'video' ? 'object-contain bg-black' : 'object-cover'
}`}
@@ -399,7 +403,7 @@ export default function JourneyPublicPage() {
<ClipTile />
) : (
<img
src={photoUrl(photos[2], token!, 'thumbnail')}
src={photoUrl(photos[2], token!, 'preview')}
alt=""
className={`h-full w-full ${photos[2].media_type === 'video' ? 'object-contain bg-black' : 'object-cover'
}`}
@@ -718,7 +722,7 @@ export default function JourneyPublicPage() {
dark={document.documentElement.classList.contains('dark')}
readOnly
onEntryClick={(entry) => setViewingEntry(entry as any)}
publicPhotoUrl={(photoId) => `/api/public/journey/${token}/photos/${photoId}/thumbnail`}
publicPhotoUrl={(photoId) => `/api/public/journey/${token}/photos/${photoId}/preview`}
carouselBottom="calc(env(safe-area-inset-bottom, 16px) + 8px)"
cartoApiKey={cartoApiKey}
layers={mapLayers}
@@ -170,7 +170,7 @@ describe('JourneyPublicPage wiring', () => {
it('FE-JRN-PUBWIRE-009: a two-photo entry opens the lightbox at the clicked index', () => {
const { hook } = setup({ timelineEntries: [buildEntry({ photos: [photo(1), photo(2)] })] });
fireEvent.click(document.querySelector('img[src="/api/public/journey/tok-1/photos/20/thumbnail"]')!);
fireEvent.click(document.querySelector('img[src="/api/public/journey/tok-1/photos/20/preview"]')!);
expect(hook.setLightbox).toHaveBeenCalledWith(expect.objectContaining({ index: 1 }));
});
@@ -181,7 +181,7 @@ describe('JourneyPublicPage wiring', () => {
expect(screen.getByText('+1')).toBeInTheDocument();
for (const [photoId, index] of [[10, 0], [20, 1], [30, 2]] as const) {
fireEvent.click(document.querySelector(`img[src="/api/public/journey/tok-1/photos/${photoId}/thumbnail"]`)!.parentElement!);
fireEvent.click(document.querySelector(`img[src="/api/public/journey/tok-1/photos/${photoId}/preview"]`)!.parentElement!);
expect(hook.setLightbox).toHaveBeenLastCalledWith(expect.objectContaining({ index }));
}
});
@@ -272,9 +272,10 @@ describe('JourneyPublicPage wiring', () => {
// The cover card draws this URL in an <img>, so it has to be the poster, not
// the file itself: /original is the clip for a video and a full-size JPEG for
// a photo (#2341). The own-journey cover already asks for /thumbnail.
// a photo (#2341). It fills the card, so it is the preview, as the
// own-journey cover's is (#2874).
const publicPhotoUrl = mocks.captured.mobileTimeline.publicPhotoUrl as (id: number) => string;
expect(publicPhotoUrl(55)).toBe('/api/public/journey/tok-1/photos/55/thumbnail');
expect(publicPhotoUrl(55)).toBe('/api/public/journey/tok-1/photos/55/preview');
(mocks.captured.mobileTimeline.onEntryClick as (e: PublicEntry) => void)(buildEntry({ id: 9 }));
expect(hook.setViewingEntry).toHaveBeenCalledWith(expect.objectContaining({ id: 9 }));
@@ -85,7 +85,11 @@ export function formatDate(d: string, locale?: string): { weekday: string; month
};
}
export function photoUrl(p: { photo_id: number }, size: 'thumbnail' | 'original' = 'thumbnail'): string {
/**
* A journey photo's address. `preview` is the medium rendition for a large tile
* (#2874): the thumbnail drew blurry there, the original is far more than it shows.
*/
export function photoUrl(p: { photo_id: number }, size: 'thumbnail' | 'preview' | 'original' = 'thumbnail'): string {
return `/api/photos/${p.photo_id}/${size}`;
}