mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
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:
@@ -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"
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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}`;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,15 @@ import { journeyPublicMapLayersResponseSchema, journeyPublicResponseSchema } fro
|
||||
import type { Response } from 'express';
|
||||
import path from 'node:path';
|
||||
|
||||
/**
|
||||
* The size a share link's photo route was asked for. Anything but the two
|
||||
* smaller renditions is the original, as it has always been; `preview` (#2874)
|
||||
* used to fall into that and sent the full image to a large tile.
|
||||
*/
|
||||
function sharedPhotoKind(kind: string): 'thumbnail' | 'preview' | 'original' {
|
||||
return kind === 'thumbnail' || kind === 'preview' ? kind : 'original';
|
||||
}
|
||||
|
||||
/**
|
||||
* /api/public/journey — unauthenticated, share-token validated read + photo
|
||||
* proxy for publicly shared journeys.
|
||||
@@ -85,7 +94,7 @@ export class JourneyPublicController {
|
||||
if (!valid) {
|
||||
throw new HttpException({ error: 'Not found' }, 404);
|
||||
}
|
||||
await this.journey.streamPhoto(res, valid.ownerId, photoId, kind === 'thumbnail' ? 'thumbnail' : 'original');
|
||||
await this.journey.streamPhoto(res, valid.ownerId, photoId, sharedPhotoKind(kind));
|
||||
}
|
||||
|
||||
@Get(':token/photo/:provider/:assetId/:ownerId/:kind')
|
||||
@@ -101,7 +110,7 @@ export class JourneyPublicController {
|
||||
throw new HttpException({ error: 'Not found' }, 404);
|
||||
}
|
||||
|
||||
const wantThumb = kind === 'thumbnail' ? 'thumbnail' : 'original';
|
||||
const wanted = sharedPhotoKind(kind);
|
||||
|
||||
if (provider === 'local') {
|
||||
// Local journey assets are flat filenames. basename() kept for shape;
|
||||
@@ -134,7 +143,7 @@ export class JourneyPublicController {
|
||||
res,
|
||||
provider,
|
||||
{ userId: effectiveOwnerId, ownerId: effectiveOwnerId, assetId },
|
||||
wantThumb,
|
||||
wanted,
|
||||
);
|
||||
if (streaming === null) {
|
||||
res.status(404).json({ error: 'Provider not supported' });
|
||||
|
||||
@@ -184,7 +184,7 @@ export class JourneyService {
|
||||
return this.share.validateShareTokenForAsset(token, assetId);
|
||||
}
|
||||
/** The public share's photo bytes: local files go out without their location. */
|
||||
streamPhoto(res: Response, ownerId: number, photoId: number, kind: 'thumbnail' | 'original') {
|
||||
streamPhoto(res: Response, ownerId: number, photoId: number, kind: 'thumbnail' | 'preview' | 'original') {
|
||||
return this.photoResolver.streamPublicPhoto(res, ownerId, photoId, kind);
|
||||
}
|
||||
/**
|
||||
@@ -201,7 +201,7 @@ export class JourneyService {
|
||||
res: Response,
|
||||
provider: string,
|
||||
ref: { userId: number; ownerId: number; assetId: string },
|
||||
kind: 'thumbnail' | 'original',
|
||||
kind: 'thumbnail' | 'preview' | 'original',
|
||||
): Promise<void> | null {
|
||||
const backend = this.providers.get(provider);
|
||||
if (!backend) return null;
|
||||
|
||||
@@ -544,7 +544,7 @@ export class ImmichService {
|
||||
response: Response,
|
||||
userId: number,
|
||||
assetId: string,
|
||||
kind: 'thumbnail' | 'original',
|
||||
kind: 'thumbnail' | 'preview' | 'original',
|
||||
ownerUserId?: number,
|
||||
opts?: { mediaType?: string | null; range?: string; publicView?: boolean },
|
||||
): Promise<void> {
|
||||
@@ -572,6 +572,12 @@ export class ImmichService {
|
||||
// Immich generates a poster thumbnail for video too.
|
||||
url = `${creds.immich_url}/api/assets/${assetId}/thumbnail?size=thumbnail`;
|
||||
timeout = 10000;
|
||||
} else if (kind === 'preview') {
|
||||
// The medium rendition for a large tile (#2874), a video's poster at that
|
||||
// size too. Re-encoded without the stored metadata, so a share link's
|
||||
// viewer may have it as well.
|
||||
url = `${creds.immich_url}/api/assets/${assetId}/thumbnail?size=preview`;
|
||||
timeout = 30000;
|
||||
} else if (isVideo) {
|
||||
// Transcoded, broadly-compatible MP4 with byte-range support; forward the
|
||||
// viewer's Range so the player can seek. No abort timeout — video is a long
|
||||
|
||||
@@ -2,8 +2,14 @@ import type { AssetInfo, ServiceResult } from './memories.helpers';
|
||||
|
||||
import type { Response } from 'express';
|
||||
|
||||
/** What a caller can ask a provider for. */
|
||||
export type PhotoAssetKind = 'thumbnail' | 'original';
|
||||
/**
|
||||
* What a caller can ask a provider for. `preview` is the medium rendition a
|
||||
* large tile needs (#2874): the small thumbnail drew blurry there, the original
|
||||
* is far more than a tile shows. A provider sends its own re-encoded
|
||||
* rendition of that size (Immich `preview`, Synology `xl`), never the file as
|
||||
* stored, so it is safe for a share link's viewer too.
|
||||
*/
|
||||
export type PhotoAssetKind = 'thumbnail' | 'preview' | 'original';
|
||||
|
||||
/**
|
||||
* One asset, and everything a provider needs to reach it.
|
||||
|
||||
@@ -3,7 +3,7 @@ import { decrypt_api_key } from '../common/crypto/apiKeyCrypto';
|
||||
import { TrekPhotoRegistrationService } from '../photos/trek-photo-registration.service';
|
||||
import { StorageService } from '../storage/storage.service';
|
||||
import { fail, success, type AssetInfo, type ServiceResult } from './memories.helpers';
|
||||
import type { PhotoAssetRef } from './photo-provider';
|
||||
import type { PhotoAssetKind, PhotoAssetRef } from './photo-provider';
|
||||
import { PhotoProviderRegistry } from './photo-provider.registry';
|
||||
import { answerRenditionPending, pendingOrNone, PublicMediaService, RENDITION_PENDING } from './public-media.service';
|
||||
import { ThumbnailService } from './thumbnail.service';
|
||||
@@ -96,7 +96,7 @@ export class PhotoResolverService {
|
||||
res: Response,
|
||||
userId: number,
|
||||
photoId: number,
|
||||
kind: 'thumbnail' | 'original',
|
||||
kind: PhotoAssetKind,
|
||||
range?: string,
|
||||
): Promise<void> {
|
||||
await this.stream(res, userId, photoId, kind, range, 'owner');
|
||||
@@ -113,7 +113,7 @@ export class PhotoResolverService {
|
||||
res: Response,
|
||||
ownerId: number,
|
||||
photoId: number,
|
||||
kind: 'thumbnail' | 'original',
|
||||
kind: PhotoAssetKind,
|
||||
): Promise<void> {
|
||||
await this.stream(res, ownerId, photoId, kind, undefined, 'public');
|
||||
}
|
||||
@@ -163,7 +163,7 @@ export class PhotoResolverService {
|
||||
res: Response,
|
||||
userId: number,
|
||||
photoId: number,
|
||||
kind: 'thumbnail' | 'original',
|
||||
kind: PhotoAssetKind,
|
||||
range: string | undefined,
|
||||
audience: Audience,
|
||||
): Promise<void> {
|
||||
@@ -174,7 +174,9 @@ export class PhotoResolverService {
|
||||
}
|
||||
|
||||
if (photo.file_path) {
|
||||
if (kind === 'thumbnail') {
|
||||
// A local photo's thumbnail is already the medium size (ThumbnailService,
|
||||
// 800 px), so it is the preview too.
|
||||
if (kind === 'thumbnail' || kind === 'preview') {
|
||||
const thumbRel = await this.localThumbnail(photo);
|
||||
if (thumbRel && (await this.sendLocal(res, thumbRel, audience, THUMB_CACHE))) return;
|
||||
// A poster-less video must NOT fall through to streaming the whole file as a
|
||||
@@ -220,7 +222,8 @@ export class PhotoResolverService {
|
||||
);
|
||||
return;
|
||||
}
|
||||
await provider.streamAsset(res, { ...ref, range, audience }, kind);
|
||||
// Only the original is seekable: a preview is one image and carries no Range.
|
||||
await provider.streamAsset(res, { ...ref, range: kind === 'original' ? range : undefined, audience }, kind);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -848,7 +848,7 @@ export class SynologyService {
|
||||
userId: number,
|
||||
targetUserId: number,
|
||||
photoId: string,
|
||||
kind: 'thumbnail' | 'original',
|
||||
kind: 'thumbnail' | 'preview' | 'original',
|
||||
size?: string,
|
||||
passphrase?: string,
|
||||
): Promise<void> {
|
||||
@@ -878,8 +878,9 @@ export class SynologyService {
|
||||
// Use Thumbnail API for both thumbnail and original — avoids serving raw HEIC files
|
||||
// (original uses xl size to get a full-resolution JPEG-compatible render).
|
||||
// Thumbnail default is 'm' (~320px) — 'sm' (240px) looked pixelated on
|
||||
// the journey grid on retina screens.
|
||||
const resolvedSize = kind === 'original' ? 'xl' : size || 'm';
|
||||
// the journey grid on retina screens. A preview is the large tiles' 'xl'
|
||||
// (#2874), whatever size the caller named.
|
||||
const resolvedSize = kind === 'thumbnail' ? size || 'm' : 'xl';
|
||||
const params = new URLSearchParams({
|
||||
api: 'SYNO.Foto.Thumbnail',
|
||||
method: 'get',
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Controller, Get, Headers, HttpException, Param, Res, UseGuards } from '
|
||||
import type { Response } from 'express';
|
||||
|
||||
/**
|
||||
* /api/photos/:id/{thumbnail,original,info} — global (not trip-scoped) photo
|
||||
* /api/photos/:id/{thumbnail,preview,original,info} — global (not trip-scoped) photo
|
||||
* access for the memories/journey features. Streaming endpoints write straight
|
||||
* to the response via the resolver service.
|
||||
*
|
||||
@@ -39,6 +39,18 @@ export class PhotosController {
|
||||
await this.photos.stream(res, user.id, photoId, 'thumbnail');
|
||||
}
|
||||
|
||||
/**
|
||||
* The medium rendition for a large tile (#2874): the provider's preview
|
||||
* (Immich `preview`, Synology `xl`), a local photo's 800 px thumbnail. Same
|
||||
* access check as the other two.
|
||||
*/
|
||||
// response-contract-exempt: streams the image bytes through @Res(), there is no JSON body to check.
|
||||
@Get(':id/preview')
|
||||
async preview(@CurrentUser() user: User, @Param('id') id: string, @Res() res: Response): Promise<void> {
|
||||
const photoId = await this.requireAccess(user, id);
|
||||
await this.photos.stream(res, user.id, photoId, 'preview');
|
||||
}
|
||||
|
||||
@Get(':id/original')
|
||||
async original(
|
||||
@CurrentUser() user: User,
|
||||
|
||||
@@ -20,7 +20,7 @@ export class PhotosService {
|
||||
return this.access.canAccessTrekPhoto(userId, photoId);
|
||||
}
|
||||
|
||||
stream(res: Response, userId: number, photoId: number, kind: 'thumbnail' | 'original', range?: string) {
|
||||
stream(res: Response, userId: number, photoId: number, kind: 'thumbnail' | 'preview' | 'original', range?: string) {
|
||||
return this.resolver.streamPhoto(res, userId, photoId, kind, range);
|
||||
}
|
||||
|
||||
|
||||
@@ -225,4 +225,15 @@ describe('Files + photos e2e (real auth guard + temp SQLite)', () => {
|
||||
expect(res.status).toBe(403);
|
||||
expect(res.body).toEqual({ error: 'Forbidden' });
|
||||
});
|
||||
|
||||
it('the preview route answers 401 without a session, 400 for a bad id and 403 without access (#2874)', async () => {
|
||||
expect((await request(server).get('/api/photos/5/preview')).status).toBe(401);
|
||||
const bad = await request(server).get('/api/photos/abc/preview').set('Cookie', sessionCookie(1));
|
||||
expect(bad.status).toBe(400);
|
||||
expect(bad.body).toEqual({ error: 'Invalid photo ID' });
|
||||
helperSvc.canAccessTrekPhoto.mockReturnValue(false);
|
||||
const denied = await request(server).get('/api/photos/5/preview').set('Cookie', sessionCookie(1));
|
||||
expect(denied.status).toBe(403);
|
||||
expect(denied.body).toEqual({ error: 'Forbidden' });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -704,6 +704,27 @@ describe('Synology asset access', () => {
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
|
||||
it('SYNO-032c — GET /api/photos/:id/preview asks Synology for its xl rendition (#2874)', async () => {
|
||||
const { user } = await makeUser(orm);
|
||||
await setSynologyCredentials(orm, user.id, 'https://synology.example.com', 'admin', 'pass');
|
||||
const trekPhotoId = await insertRow(orm, TrekPhotos, {
|
||||
provider: 'synologyphotos',
|
||||
asset_id: '101_cachekey',
|
||||
owner: user.id,
|
||||
});
|
||||
vi.mocked(safeFetch).mockClear();
|
||||
|
||||
const res = await request(app).get(`/api/photos/${trekPhotoId}/preview`).set('Cookie', authCookie(user.id));
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
const sizes = vi
|
||||
.mocked(safeFetch)
|
||||
.mock.calls.map((call) => new URL(String(call[0])))
|
||||
.filter((url) => url.searchParams.get('api') === 'SYNO.Foto.Thumbnail')
|
||||
.map((url) => url.searchParams.get('size'));
|
||||
expect(sizes).toEqual(['xl']);
|
||||
});
|
||||
|
||||
it('SYNO-033 — GET /assets/original streams image data for shared photo', async () => {
|
||||
const { user: owner } = await makeUser(orm);
|
||||
const { user: member } = await makeUser(orm);
|
||||
|
||||
@@ -691,6 +691,15 @@ describe('PhotosController', () => {
|
||||
expect(stream).toHaveBeenCalledWith(res, 1, 5, 'original', undefined);
|
||||
});
|
||||
|
||||
it('streams the preview a large tile asks for, behind the same id and access checks (#2874)', async () => {
|
||||
const stream = vi.fn().mockResolvedValue(undefined);
|
||||
await new PhotosController(psvc({ stream })).preview(user2, '5', res);
|
||||
expect(stream).toHaveBeenCalledWith(res, 1, 5, 'preview');
|
||||
await expect(new PhotosController(psvc()).preview(user2, '0x5', res)).rejects.toMatchObject({ status: 400 });
|
||||
const denied = new PhotosController(psvc({ canAccess: vi.fn().mockReturnValue(false) }));
|
||||
await expect(denied.preview(user2, '5', res)).rejects.toMatchObject({ status: 403 });
|
||||
});
|
||||
|
||||
it('info writes the data, maps a service error', async () => {
|
||||
const okRes = { status: vi.fn().mockReturnThis(), json: vi.fn() } as unknown as Response;
|
||||
await new PhotosController(psvc({ info: vi.fn().mockResolvedValue({ data: { id: '5' } }) })).info(
|
||||
|
||||
@@ -988,6 +988,23 @@ describe('streamImmichAsset', () => {
|
||||
expect(urls[2]).toContain('/api/assets/v1/video/playback');
|
||||
});
|
||||
|
||||
it('IMMICH-041f: a preview asks Immich for its preview rendition, a video its poster at that size (#2874)', async () => {
|
||||
await seedUser(13, 'https://immich.example', 'owner-key');
|
||||
safeFetch.mockResolvedValue(upstream({ contentType: 'image/jpeg', body: 'bytes' }));
|
||||
|
||||
await svc.streamImmichAsset(makeRes() as never, USER, 'a1', 'preview', 13);
|
||||
await svc.streamImmichAsset(makeRes() as never, USER, 'v1', 'preview', 13, {
|
||||
mediaType: 'video',
|
||||
publicView: true,
|
||||
});
|
||||
|
||||
const urls = safeFetch.mock.calls.map((call) => String(call[0]));
|
||||
expect(urls).toEqual([
|
||||
expect.stringContaining('/api/assets/a1/thumbnail?size=preview'),
|
||||
expect.stringContaining('/api/assets/v1/thumbnail?size=preview'),
|
||||
]);
|
||||
});
|
||||
|
||||
describe('a public video', () => {
|
||||
const located = { exifInfo: { latitude: 38.1, longitude: 13.1, fileSizeInByte: 5000 } };
|
||||
const playback = (total: number) => ({
|
||||
|
||||
@@ -1191,6 +1191,23 @@ describe('JourneyPublicController', () => {
|
||||
expect(streamPhoto).toHaveBeenCalledWith({}, 3, 7, 'thumbnail');
|
||||
});
|
||||
|
||||
it('both photo proxies hand a preview on as one (#2874), and any other size as the original', async () => {
|
||||
const streamPhoto = vi.fn().mockResolvedValue(undefined);
|
||||
const streamProviderAsset = vi.fn().mockResolvedValue(undefined);
|
||||
const s = svc({
|
||||
validateShareTokenForPhoto: vi.fn().mockReturnValue({ ownerId: 3 }),
|
||||
validateShareTokenForAsset: vi.fn().mockReturnValue({ ownerId: 3 }),
|
||||
streamPhoto,
|
||||
streamProviderAsset,
|
||||
} as Partial<JourneyService>);
|
||||
const proxy = new JourneyPublicController(s, storageStub, publicMediaStub);
|
||||
await proxy.photo('tok', 7, 'preview', {} as Response);
|
||||
await proxy.photo('tok', 7, 'huge', {} as Response);
|
||||
await proxy.legacyPhoto('tok', 'immich', 'a1', 'preview', {} as Response);
|
||||
expect(streamPhoto.mock.calls.map((call) => call[3])).toEqual(['preview', 'original']);
|
||||
expect(streamProviderAsset).toHaveBeenCalledWith({}, 'immich', { userId: 3, ownerId: 3, assetId: 'a1' }, 'preview');
|
||||
});
|
||||
|
||||
it('legacy photo proxy: synology streams, and a failure becomes a 404 json', async () => {
|
||||
const streamProviderAsset = vi.fn().mockResolvedValue(undefined);
|
||||
const s = svc({
|
||||
|
||||
@@ -443,6 +443,56 @@ describe('streamPhoto — dispatch', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('streamPhoto — the preview a large tile asks for (#2874)', () => {
|
||||
it('RESOLVE-040: a local photo answers its 800 px thumbnail, for the owner and for a share link alike', async () => {
|
||||
const id = await insertPhoto({
|
||||
provider: 'local',
|
||||
file_path: 'journey/x.jpg',
|
||||
thumbnail_path: 'journey/thumbs/h.jpg',
|
||||
});
|
||||
storage.exists.mockResolvedValue(true);
|
||||
const res = makeRes();
|
||||
|
||||
await svc.streamPhoto(res as never, 1, id, 'preview');
|
||||
await svc.streamPublicPhoto(res as never, 1, id, 'preview');
|
||||
|
||||
expect(storage.sendToResponse.mock.calls.map((call) => call[1])).toEqual(['thumbs/h.jpg', 'thumbs/h.jpg']);
|
||||
expect(publicMedia.renditionFor).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('RESOLVE-041: a local video without a poster answers 404 rather than the whole clip', async () => {
|
||||
const id = await insertPhoto({ provider: 'local', file_path: 'journey/clip.mp4', media_type: 'video' });
|
||||
storage.exists.mockResolvedValue(true);
|
||||
const res = makeRes();
|
||||
|
||||
await svc.streamPhoto(res as never, 1, id, 'preview');
|
||||
|
||||
expect(res.status).toHaveBeenCalledWith(404);
|
||||
expect(res.json).toHaveBeenCalledWith({ error: 'No poster available' });
|
||||
expect(storage.sendToResponse).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('RESOLVE-042: a provider photo is asked for its preview past the thumbnail cache, without the Range', async () => {
|
||||
const immichId = await insertPhoto({ provider: 'immich', asset_id: 'a1', owner_id: 5 });
|
||||
const synologyId = await insertPhoto({ provider: 'synologyphotos', asset_id: 's1', owner_id: 9 });
|
||||
const res = makeRes();
|
||||
|
||||
await svc.streamPhoto(res as never, 3, immichId, 'preview', 'bytes=0-99');
|
||||
await svc.streamPhoto(res as never, 4, synologyId, 'preview');
|
||||
|
||||
expect(cache.serveFresh).not.toHaveBeenCalled();
|
||||
expect(immich.streamImmichAsset).toHaveBeenCalledWith(
|
||||
res,
|
||||
3,
|
||||
'a1',
|
||||
'preview',
|
||||
5,
|
||||
expect.objectContaining({ range: undefined, publicView: false }),
|
||||
);
|
||||
expect(synology.streamSynologyAsset).toHaveBeenCalledWith(res, 4, 9, 's1', 'preview', undefined, undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPhotoInfo — dispatch', () => {
|
||||
it('RESOLVE-010: rejects an unknown photo id', async () => {
|
||||
const result = await svc.getPhotoInfo(1, 999999);
|
||||
|
||||
Reference in New Issue
Block a user