mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 02:14:05 +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:
@@ -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