#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:
trecoool
2026-08-24 14:35:28 +02:00
parent 8c2c2219ce
commit 4021c66cec
17 changed files with 384 additions and 23 deletions
+19 -4
View File
@@ -34,6 +34,14 @@ function galleryProps (item: Partial<GalleryItem>): GalleryProps {
const payload = '</script><script>alert(1)</script>'
/** Render a gallery and parse back the `#ipp-init` JSON block the client reads. */
function initParams (props: GalleryProps) {
const html = renderPage(h(Gallery, props))
const match = html.match(/<script type="application\/json" id="ipp-init">(.*?)<\/script>/s)
if (!match) throw new Error('No init JSON block in the rendered gallery')
return JSON.parse(match[1])
}
describe('gallery init JSON escaping', () => {
it('neutralises </script> in a crafted download filename', () => {
const html = renderPage(h(Gallery, galleryProps({ downloadFilename: payload })))
@@ -50,10 +58,17 @@ describe('gallery init JSON escaping', () => {
})
it('still produces JSON the client can parse back to the same items', () => {
const html = renderPage(h(Gallery, galleryProps({ downloadFilename: payload })))
const match = html.match(/<script type="application\/json" id="ipp-init">(.*?)<\/script>/s)
expect(match).not.toBeNull()
const params = JSON.parse(match![1])
// initParams throws if the block is missing, so reaching the assertion
// also proves the block is still there and still parses.
const params = initParams(galleryProps({ downloadFilename: payload }))
expect(params.items[0].downloadFilename).toBe(payload)
})
it('serialises motionUrl for a motion photo, and omits the key otherwise', () => {
const motionUrl = '/share/video/k/dddddddd-dddd-dddd-dddd-dddddddddddd'
expect(initParams(galleryProps({ motionUrl })).items[0].motionUrl).toBe(motionUrl)
// Absent (not null / empty string), so the client's `item.motionUrl` check
// and the tile badge stay off for ordinary photos.
expect(initParams(galleryProps({})).items[0]).not.toHaveProperty('motionUrl')
})
})