#200 motion photo (Live Photo) support
Show a badge on the gallery thumbnail and a lightbox toggle that plays the photo's clip over the still, matching Immich's own viewer. The clip is a hidden Immich asset, but the existing share key already authorises it - checkSharedLinkAccess whitelists each shared asset's livePhotoVideoId - so no new upstream access is involved. The video route accepts a clip id only when a shared still points at it. Both enumeration paths already carry the field (AssetResponseDto for individual shares, TimeBucketAssetResponseDto for album buckets), so album shares cost no extra upstream requests. Gated by ipp.motionPhotos (default true). The clip is preload="none" and is only fetched when a visitor presses the toggle.
This commit is contained in:
+20
-6
@@ -23,7 +23,7 @@ import { Asset, AssetType, ImageSize, KeyType, SharedLink } from './types'
|
||||
import { getConfigOption } from './config/access'
|
||||
import { loadConfig } from './config/loader'
|
||||
import { addResponseHeaders, asyncHandler, errorHandler } from './http'
|
||||
import { canDownload } from './share'
|
||||
import { canDownload, findMotionPhotoStill } from './share'
|
||||
import { toString } from './utils/text'
|
||||
import { decrypt, encrypt } from './encrypt'
|
||||
import { respondToInvalidRequest } from './invalidRequestHandler'
|
||||
@@ -121,7 +121,7 @@ async function resolveShare (req: Request, keyType: KeyType): Promise<ShareResol
|
||||
return { ok: true, link: share.link }
|
||||
}
|
||||
|
||||
async function resolveSharedAsset (req: Request, keyType: KeyType): Promise<SharedAssetResolution> {
|
||||
async function resolveSharedAsset (req: Request, keyType: KeyType, allowMotion = false): Promise<SharedAssetResolution> {
|
||||
if (!isId(req.params.id)) {
|
||||
return { ok: false, status: 404, reason: 'Invalid ID for ' + req.path }
|
||||
}
|
||||
@@ -130,10 +130,24 @@ async function resolveSharedAsset (req: Request, keyType: KeyType): Promise<Shar
|
||||
// Confirm the asset belongs to this share (defence in depth - Immich also
|
||||
// enforces this via the share key).
|
||||
const asset = resolved.link.assets.find(a => a.id === req.params.id)
|
||||
if (!asset) {
|
||||
return { ok: false, status: 404, reason: 'Asset not found in share' }
|
||||
if (asset) return { ok: true, link: resolved.link, asset }
|
||||
// A motion photo's clip is a hidden asset that never appears in the share's
|
||||
// own asset list, but Immich authorises it under the same key. Accept it only
|
||||
// for the video route, and only when a shared still actually points at it -
|
||||
// the whitelist stays bounded by the share's contents.
|
||||
if (allowMotion) {
|
||||
const parent = findMotionPhotoStill(resolved.link, req.params.id)
|
||||
if (parent) {
|
||||
return {
|
||||
ok: true,
|
||||
link: resolved.link,
|
||||
// The clip streams inline from /video/playback, so the still's filename
|
||||
// and mime must not follow it into Content-Disposition / sizing.
|
||||
asset: { ...parent, id: req.params.id, type: AssetType.video, originalFileName: undefined, originalMimeType: undefined }
|
||||
}
|
||||
}
|
||||
}
|
||||
return { ok: true, link: resolved.link, asset }
|
||||
return { ok: false, status: 404, reason: 'Asset not found in share' }
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -253,7 +267,7 @@ app.get('/share/:type(photo|video)/:key/:id/:size?', decodeCookie, asyncHandler(
|
||||
// The resolved asset gives assetBuffer access to originalMimeType and
|
||||
// originalFileName (needed for Content-Disposition and for requiresOriginal
|
||||
// to recognise videos/animated images and bypass the preview downgrade).
|
||||
const resolved = await resolveSharedAsset(req, KeyType.key)
|
||||
const resolved = await resolveSharedAsset(req, KeyType.key, req.params.type === 'video')
|
||||
if (!resolved.ok) {
|
||||
// Password-protected: redirect to the share page so the visitor gets the
|
||||
// unlock prompt, rather than returning an error.
|
||||
|
||||
Reference in New Issue
Block a user