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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user