Size motion photo clip to the still and make the toggle sticky #286
This commit is contained in:
@@ -139,14 +139,12 @@ html.pswp-no-arrows .pswp__button--arrow {
|
|||||||
background: #000;
|
background: #000;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Motion photo (Live Photo) clip. It lives inside the slide's zoom wrap, which
|
/* Motion photo (Live Photo) clip, inside the slide's zoom wrap so it follows
|
||||||
carries PhotoSwipe's pan/zoom transform, so it stays pinned to the still
|
PhotoSwipe's pan / zoom. Width / height are set inline from the still. */
|
||||||
underneath through zoom, pan and resize with no geometry tracking in JS. */
|
|
||||||
.pswp__motion-video {
|
.pswp__motion-video {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
inset: 0;
|
top: 0;
|
||||||
width: 100%;
|
left: 0;
|
||||||
height: 100%;
|
|
||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
pointer-events: none; /* PhotoSwipe keeps handling drag / zoom / swipe */
|
pointer-events: none; /* PhotoSwipe keeps handling drag / zoom / swipe */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,7 @@ export const ICON_FULLSCREEN = '<svg class="pswp__icn" viewBox="0 0 24 24" aria-
|
|||||||
export const ICON_FULLSCREEN_EXIT = '<svg class="pswp__icn" viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M14,14H19V16H16V19H14V14M5,14H10V19H8V16H5V14M8,5H10V10H5V8H8V5M19,8V10H14V5H16V8H19Z"/></svg>'
|
export const ICON_FULLSCREEN_EXIT = '<svg class="pswp__icn" viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M14,14H19V16H16V19H14V14M5,14H10V19H8V16H5V14M8,5H10V10H5V8H8V5M19,8V10H14V5H16V8H19Z"/></svg>'
|
||||||
export const ICON_INFO = '<svg class="pswp__icn" viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z"/></svg>'
|
export const ICON_INFO = '<svg class="pswp__icn" viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z"/></svg>'
|
||||||
export const ICON_BACK = '<svg class="pswp__icn" viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z"/></svg>'
|
export const ICON_BACK = '<svg class="pswp__icn" viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z"/></svg>'
|
||||||
// Motion photo (Live Photo) toggle - play when stopped, pause while the
|
// Motion photo (Live Photo) toggle, off / on. Same pair as Immich's viewer.
|
||||||
// clip is running. Same pair Immich uses in its own asset viewer.
|
|
||||||
export const ICON_MOTION_PLAY = '<svg class="pswp__icn" viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M10 16.5L16 12L10 7.5M22 12C22 6.46 17.54 2 12 2C10.83 2 9.7 2.19 8.62 2.56L9.32 4.5C10.17 4.16 11.06 3.97 12 3.97C16.41 3.97 20.03 7.59 20.03 12C20.03 16.41 16.41 20.03 12 20.03C7.59 20.03 3.97 16.41 3.97 12C3.97 11.06 4.16 10.12 4.5 9.28L2.56 8.62C2.19 9.7 2 10.83 2 12C2 17.54 6.46 22 12 22C17.54 22 22 17.54 22 12M5.47 3.97C6.32 3.97 7 4.68 7 5.47C7 6.32 6.32 7 5.47 7C4.68 7 3.97 6.32 3.97 5.47C3.97 4.68 4.68 3.97 5.47 3.97Z"/></svg>'
|
export const ICON_MOTION_PLAY = '<svg class="pswp__icn" viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M10 16.5L16 12L10 7.5M22 12C22 6.46 17.54 2 12 2C10.83 2 9.7 2.19 8.62 2.56L9.32 4.5C10.17 4.16 11.06 3.97 12 3.97C16.41 3.97 20.03 7.59 20.03 12C20.03 16.41 16.41 20.03 12 20.03C7.59 20.03 3.97 16.41 3.97 12C3.97 11.06 4.16 10.12 4.5 9.28L2.56 8.62C2.19 9.7 2 10.83 2 12C2 17.54 6.46 22 12 22C17.54 22 22 17.54 22 12M5.47 3.97C6.32 3.97 7 4.68 7 5.47C7 6.32 6.32 7 5.47 7C4.68 7 3.97 6.32 3.97 5.47C3.97 4.68 4.68 3.97 5.47 3.97Z"/></svg>'
|
||||||
export const ICON_MOTION_PAUSE = '<svg class="pswp__icn" viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M22 12C22 6.46 17.54 2 12 2C10.83 2 9.7 2.19 8.62 2.56L9.32 4.5C10.17 4.16 11.06 3.97 12 3.97C16.41 3.97 20.03 7.59 20.03 12C20.03 16.41 16.41 20.03 12 20.03C7.59 20.03 3.97 16.41 3.97 12C3.97 11.06 4.16 10.12 4.5 9.28L2.56 8.62C2.19 9.7 2 10.83 2 12C2 17.54 6.46 22 12 22C17.54 22 22 17.54 22 12M5.47 7C4.68 7 3.97 6.32 3.97 5.47C3.97 4.68 4.68 3.97 5.47 3.97C6.32 3.97 7 4.68 7 5.47C7 6.32 6.32 7 5.47 7M9 9H11V15H9M13 9H15V15H13"/></svg>'
|
export const ICON_MOTION_PAUSE = '<svg class="pswp__icn" viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M22 12C22 6.46 17.54 2 12 2C10.83 2 9.7 2.19 8.62 2.56L9.32 4.5C10.17 4.16 11.06 3.97 12 3.97C16.41 3.97 20.03 7.59 20.03 12C20.03 16.41 16.41 20.03 12 20.03C7.59 20.03 3.97 16.41 3.97 12C3.97 11.06 4.16 10.12 4.5 9.28L2.56 8.62C2.19 9.7 2 10.83 2 12C2 17.54 6.46 22 12 22C17.54 22 22 17.54 22 12M5.47 7C4.68 7 3.97 6.32 3.97 5.47C3.97 4.68 4.68 3.97 5.47 3.97C6.32 3.97 7 4.68 7 5.47C7 6.32 6.32 7 5.47 7M9 9H11V15H9M13 9H15V15H13"/></svg>'
|
||||||
export const ICON_CLOSE = '<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z"/></svg>'
|
export const ICON_CLOSE = '<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z"/></svg>'
|
||||||
@@ -32,6 +31,5 @@ export const ICON_MAP = '<svg viewBox="0 0 24 24" aria-hidden="true"><path fill=
|
|||||||
// Check glyph shown inside selected tiles' checkmark circle
|
// Check glyph shown inside selected tiles' checkmark circle
|
||||||
export const CHECK_SVG = '<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg>'
|
export const CHECK_SVG = '<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg>'
|
||||||
|
|
||||||
// Motion photo indicator drawn in the corner of a gallery tile. Same glyph
|
// Tile-corner motion badge: ICON_MOTION_PLAY without the `pswp__icn` sizing.
|
||||||
// as ICON_MOTION_PLAY without PhotoSwipe's `pswp__icn` sizing class.
|
|
||||||
export const ICON_MOTION_BADGE = '<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M10 16.5L16 12L10 7.5M22 12C22 6.46 17.54 2 12 2C10.83 2 9.7 2.19 8.62 2.56L9.32 4.5C10.17 4.16 11.06 3.97 12 3.97C16.41 3.97 20.03 7.59 20.03 12C20.03 16.41 16.41 20.03 12 20.03C7.59 20.03 3.97 16.41 3.97 12C3.97 11.06 4.16 10.12 4.5 9.28L2.56 8.62C2.19 9.7 2 10.83 2 12C2 17.54 6.46 22 12 22C17.54 22 22 17.54 22 12M5.47 3.97C6.32 3.97 7 4.68 7 5.47C7 6.32 6.32 7 5.47 7C4.68 7 3.97 6.32 3.97 5.47C3.97 4.68 4.68 3.97 5.47 3.97Z"/></svg>'
|
export const ICON_MOTION_BADGE = '<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M10 16.5L16 12L10 7.5M22 12C22 6.46 17.54 2 12 2C10.83 2 9.7 2.19 8.62 2.56L9.32 4.5C10.17 4.16 11.06 3.97 12 3.97C16.41 3.97 20.03 7.59 20.03 12C20.03 16.41 16.41 20.03 12 20.03C7.59 20.03 3.97 16.41 3.97 12C3.97 11.06 4.16 10.12 4.5 9.28L2.56 8.62C2.19 9.7 2 10.83 2 12C2 17.54 6.46 22 12 22C17.54 22 22 17.54 22 12M5.47 3.97C6.32 3.97 7 4.68 7 5.47C7 6.32 6.32 7 5.47 7C4.68 7 3.97 6.32 3.97 5.47C3.97 4.68 4.68 3.97 5.47 3.97Z"/></svg>'
|
||||||
|
|||||||
@@ -171,32 +171,35 @@ export function registerFullscreenButton (lightbox: LightboxInstance) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set on the zoom wrap while a motion photo's clip is painting, so CSS can
|
// Set on the zoom wrap while a clip is painting, so CSS can fade the still out.
|
||||||
// fade the still out underneath it.
|
|
||||||
const MOTION_PLAYING_CLASS = 'pswp--motion-playing'
|
const MOTION_PLAYING_CLASS = 'pswp--motion-playing'
|
||||||
|
|
||||||
|
// Sticky: once on, every motion photo the visitor opens plays its clip until
|
||||||
|
// they turn it off. Module-level so it survives reopening the lightbox.
|
||||||
|
let motionEnabled = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `.pswp__zoom-wrap` of the slide currently on screen. Mounting the clip
|
* The `.pswp__zoom-wrap` of the current slide. It carries PhotoSwipe's pan /
|
||||||
* inside it is what makes pan / zoom free: that element carries PhotoSwipe's
|
* zoom transform, so a child at its origin follows the still for free. It has
|
||||||
* transform, so an `inset: 0` child stays pinned to the photo without any
|
* no box of its own though (auto width / height, absolute children), so the
|
||||||
* geometry tracking of our own.
|
* clip can't be sized from it.
|
||||||
*/
|
*/
|
||||||
function currentZoomWrap (pswp: PswpInstance): HTMLElement | null {
|
function currentZoomWrap (pswp: PswpInstance): HTMLElement | null {
|
||||||
const container = pswp.currSlide?.container
|
const container = pswp.currSlide?.container
|
||||||
if (container instanceof HTMLElement) return container
|
return container instanceof HTMLElement ? container : null
|
||||||
// Fallback for PhotoSwipe builds that don't expose the slide off `pswp`.
|
}
|
||||||
const fallback = pswp.element.querySelector('.pswp__item[aria-hidden="false"] .pswp__zoom-wrap')
|
|
||||||
return fallback instanceof HTMLElement ? fallback : null
|
/** The loaded still in a zoom wrap (not the thumbnail placeholder), if any. */
|
||||||
|
function loadedStill (wrap: HTMLElement): HTMLElement | null {
|
||||||
|
const still = wrap.querySelector('.pswp__img:not(.pswp__img--placeholder)')
|
||||||
|
return still instanceof HTMLElement ? still : null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the motion photo (Live Photo) toggle: swaps the still for its short
|
* Register the motion photo (Live Photo) toggle. While on, each motion photo
|
||||||
* clip and returns to the still when the clip ends. The button hides itself on
|
* plays its clip over the still on arrival and reverts when the clip ends.
|
||||||
* slides with no clip, and the server omits `motionUrl` altogether when
|
* The button hides itself on slides without a clip. Nothing is fetched from
|
||||||
* `ipp.motionPhotos` is off, so it then never appears at all.
|
* Immich until the toggle is turned on.
|
||||||
*
|
|
||||||
* The `<video>` is created on demand with `preload="none"`: nothing is fetched
|
|
||||||
* from Immich until a visitor actually presses the button.
|
|
||||||
*/
|
*/
|
||||||
export function registerMotionButton (lightbox: LightboxInstance) {
|
export function registerMotionButton (lightbox: LightboxInstance) {
|
||||||
lightbox.on('uiRegister', () => {
|
lightbox.on('uiRegister', () => {
|
||||||
@@ -207,59 +210,87 @@ export function registerMotionButton (lightbox: LightboxInstance) {
|
|||||||
html: ICON_MOTION_PLAY,
|
html: ICON_MOTION_PLAY,
|
||||||
onInit: (el: HTMLElement, pswp: PswpInstance) => {
|
onInit: (el: HTMLElement, pswp: PswpInstance) => {
|
||||||
let video: HTMLVideoElement | null = null
|
let video: HTMLVideoElement | null = null
|
||||||
|
let sizer: ResizeObserver | null = null
|
||||||
|
let stillWatcher: MutationObserver | null = null
|
||||||
|
|
||||||
const update = () => {
|
const update = () => {
|
||||||
el.hidden = !state.items[pswp.currIndex]?.motionUrl
|
el.hidden = !state.items[pswp.currIndex]?.motionUrl
|
||||||
const label = video ? 'Stop motion photo' : 'Play motion photo'
|
const label = motionEnabled ? 'Stop playing motion photos' : 'Play motion photos'
|
||||||
el.innerHTML = video ? ICON_MOTION_PAUSE : ICON_MOTION_PLAY
|
el.innerHTML = motionEnabled ? ICON_MOTION_PAUSE : ICON_MOTION_PLAY
|
||||||
el.setAttribute('aria-label', label)
|
el.setAttribute('aria-label', label)
|
||||||
el.setAttribute('title', label)
|
el.setAttribute('title', label)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PhotoSwipe reuses slide DOM, so the clip has to be torn down on slide
|
|
||||||
// change too, not only when it reaches its end.
|
|
||||||
const stop = () => {
|
const stop = () => {
|
||||||
|
stillWatcher?.disconnect()
|
||||||
|
stillWatcher = null
|
||||||
const clip = video
|
const clip = video
|
||||||
if (!clip) return
|
if (!clip) return
|
||||||
video = null
|
video = null
|
||||||
|
sizer?.disconnect()
|
||||||
|
sizer = null
|
||||||
clip.pause()
|
clip.pause()
|
||||||
clip.parentElement?.classList.remove(MOTION_PLAYING_CLASS)
|
clip.parentElement?.classList.remove(MOTION_PLAYING_CLASS)
|
||||||
clip.remove()
|
clip.remove()
|
||||||
update()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const play = () => {
|
const play = () => {
|
||||||
|
if (video) return
|
||||||
const item = state.items[pswp.currIndex]
|
const item = state.items[pswp.currIndex]
|
||||||
const wrap = currentZoomWrap(pswp)
|
const wrap = currentZoomWrap(pswp)
|
||||||
if (!item?.motionUrl || !wrap) return
|
if (!item?.motionUrl || !wrap) return
|
||||||
|
const still = loadedStill(wrap)
|
||||||
|
if (!still) {
|
||||||
|
// PhotoSwipe appends the still after it loads, which can be after
|
||||||
|
// the slide change. Wait for it.
|
||||||
|
stillWatcher?.disconnect()
|
||||||
|
stillWatcher = new MutationObserver(() => {
|
||||||
|
if (loadedStill(wrap)) play()
|
||||||
|
})
|
||||||
|
stillWatcher.observe(wrap, { childList: true })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
stillWatcher?.disconnect()
|
||||||
|
stillWatcher = null
|
||||||
const clip = document.createElement('video')
|
const clip = document.createElement('video')
|
||||||
clip.className = 'pswp__motion-video'
|
clip.className = 'pswp__motion-video'
|
||||||
// Muted is not optional - browsers refuse programmatic playback of
|
clip.muted = true // required for programmatic playback
|
||||||
// audible media, and Immich's motion clips are silent regardless.
|
|
||||||
clip.muted = true
|
|
||||||
clip.playsInline = true
|
clip.playsInline = true
|
||||||
clip.preload = 'none'
|
clip.preload = 'none'
|
||||||
clip.src = item.motionUrl
|
clip.src = item.motionUrl
|
||||||
|
// Mirror the still's inline size, which PhotoSwipe rewrites on
|
||||||
|
// resize and after each zoom gesture.
|
||||||
|
const sizeToStill = () => {
|
||||||
|
clip.style.width = still.offsetWidth + 'px'
|
||||||
|
clip.style.height = still.offsetHeight + 'px'
|
||||||
|
}
|
||||||
|
sizeToStill()
|
||||||
|
sizer = new ResizeObserver(sizeToStill)
|
||||||
|
sizer.observe(still)
|
||||||
clip.addEventListener('ended', stop, { once: true })
|
clip.addEventListener('ended', stop, { once: true })
|
||||||
// Hide the still only once the clip is actually painting, so a slow
|
clip.addEventListener('error', stop, { once: true })
|
||||||
// clip never leaves the slide blank. The identity check keeps a late
|
// Hide the still only once the clip is painting, so a slow clip never
|
||||||
// event from a clip we already stopped from hiding the still for good.
|
// leaves the slide blank.
|
||||||
clip.addEventListener('playing', () => {
|
clip.addEventListener('playing', () => {
|
||||||
if (video === clip) wrap.classList.add(MOTION_PLAYING_CLASS)
|
if (video === clip) wrap.classList.add(MOTION_PLAYING_CLASS)
|
||||||
}, { once: true })
|
}, { once: true })
|
||||||
wrap.appendChild(clip)
|
wrap.appendChild(clip)
|
||||||
video = clip
|
video = clip
|
||||||
update()
|
|
||||||
clip.play().catch(() => stop())
|
clip.play().catch(() => stop())
|
||||||
}
|
}
|
||||||
|
|
||||||
el.addEventListener('click', () => {
|
el.addEventListener('click', () => {
|
||||||
if (video) stop()
|
motionEnabled = !motionEnabled
|
||||||
else play()
|
if (motionEnabled) play()
|
||||||
|
else stop()
|
||||||
|
update()
|
||||||
})
|
})
|
||||||
|
// Also fires for the opening slide, so this covers reopening with
|
||||||
|
// the toggle on.
|
||||||
pswp.on('change', () => {
|
pswp.on('change', () => {
|
||||||
stop()
|
stop()
|
||||||
update()
|
update()
|
||||||
|
if (motionEnabled) play()
|
||||||
})
|
})
|
||||||
pswp.on('destroy', stop)
|
pswp.on('destroy', stop)
|
||||||
update()
|
update()
|
||||||
|
|||||||
@@ -239,8 +239,7 @@ export function initLightbox () {
|
|||||||
registerBackButton(state.lightbox)
|
registerBackButton(state.lightbox)
|
||||||
if (state.lightboxConfig.showDownload) registerDownloadButton(state.lightbox)
|
if (state.lightboxConfig.showDownload) registerDownloadButton(state.lightbox)
|
||||||
registerFullscreenButton(state.lightbox)
|
registerFullscreenButton(state.lightbox)
|
||||||
// Hides itself on slides with no clip, so no config check is needed here -
|
// No config gate: the server omits `motionUrl` when motion photos are off.
|
||||||
// the server omits `motionUrl` when `ipp.motionPhotos` is off.
|
|
||||||
registerMotionButton(state.lightbox)
|
registerMotionButton(state.lightbox)
|
||||||
if (state.metadataConfig.descriptionInCaption) registerCaption(state.lightbox)
|
if (state.metadataConfig.descriptionInCaption) registerCaption(state.lightbox)
|
||||||
if (state.metadataConfig.sidebarHasContent) registerSidebar(state.lightbox)
|
if (state.metadataConfig.sidebarHasContent) registerSidebar(state.lightbox)
|
||||||
|
|||||||
@@ -79,8 +79,7 @@ export async function gallery (res: Response, share: SharedLink, openItem?: numb
|
|||||||
const fullUrl = zoomUpgrade && asset.type === AssetType.image && !requiresOriginal(asset)
|
const fullUrl = zoomUpgrade && asset.type === AssetType.image && !requiresOriginal(asset)
|
||||||
? photoUrl(share.key, asset.id, ImageSize.fullsize)
|
? photoUrl(share.key, asset.id, ImageSize.fullsize)
|
||||||
: undefined
|
: undefined
|
||||||
// Motion photo clip. Reuses the video route; Immich authorises the clip
|
// Motion photo clip, served through the video route under the same key.
|
||||||
// under the same share key.
|
|
||||||
const motionUrl = motionPhotos && asset.type === AssetType.image && asset.livePhotoVideoId
|
const motionUrl = motionPhotos && asset.type === AssetType.image && asset.livePhotoVideoId
|
||||||
? videoUrl(share.key, asset.livePhotoVideoId)
|
? videoUrl(share.key, asset.livePhotoVideoId)
|
||||||
: undefined
|
: undefined
|
||||||
|
|||||||
+3
-6
@@ -131,18 +131,15 @@ async function resolveSharedAsset (req: Request, keyType: KeyType, allowMotion =
|
|||||||
// enforces this via the share key).
|
// enforces this via the share key).
|
||||||
const asset = resolved.link.assets.find(a => a.id === req.params.id)
|
const asset = resolved.link.assets.find(a => a.id === req.params.id)
|
||||||
if (asset) return { ok: true, link: resolved.link, asset }
|
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
|
// A motion photo's clip is a hidden asset outside the share's asset list.
|
||||||
// own asset list, but Immich authorises it under the same key. Accept it only
|
// Serve it on the video route only, and only if a shared still points at it.
|
||||||
// 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) {
|
if (allowMotion) {
|
||||||
const parent = findMotionPhotoStill(resolved.link, req.params.id)
|
const parent = findMotionPhotoStill(resolved.link, req.params.id)
|
||||||
if (parent) {
|
if (parent) {
|
||||||
return {
|
return {
|
||||||
ok: true,
|
ok: true,
|
||||||
link: resolved.link,
|
link: resolved.link,
|
||||||
// The clip streams inline from /video/playback, so the still's filename
|
// Streams inline, so the still's filename / mime must not carry over.
|
||||||
// and mime must not follow it into Content-Disposition / sizing.
|
|
||||||
asset: { ...parent, id: req.params.id, type: AssetType.video, originalFileName: undefined, originalMimeType: undefined }
|
asset: { ...parent, id: req.params.id, type: AssetType.video, originalFileName: undefined, originalMimeType: undefined }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-7
@@ -80,13 +80,9 @@ function expiryDateLocale (): string | undefined {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the shared still that a motion photo (Live Photo) clip belongs to.
|
* Find the shared still that a motion photo (Live Photo) clip belongs to. The
|
||||||
*
|
* clip is a hidden asset that Immich authorises under the same share key;
|
||||||
* The clip is a separate, hidden Immich asset: it never appears in the share's
|
* requiring a shared still to point at it keeps the ids IPP serves bounded.
|
||||||
* own asset list, but Immich authorises it under the same shared-link key
|
|
||||||
* (`checkSharedLinkAccess` whitelists each shared asset's `livePhotoVideoId`).
|
|
||||||
* Matching against the share's own assets is what keeps the set of ids IPP will
|
|
||||||
* serve bounded by the share's contents.
|
|
||||||
*/
|
*/
|
||||||
export function findMotionPhotoStill (share: SharedLink, clipId: string): Asset | undefined {
|
export function findMotionPhotoStill (share: SharedLink, clipId: string): Asset | undefined {
|
||||||
if (!clipId) return undefined
|
if (!clipId) return undefined
|
||||||
|
|||||||
+1
-3
@@ -61,9 +61,7 @@ export interface Asset {
|
|||||||
height?: number;
|
height?: number;
|
||||||
// Base64-encoded thumbhash for tasteful blur placeholders during lazy-load
|
// Base64-encoded thumbhash for tasteful blur placeholders during lazy-load
|
||||||
thumbhash?: string;
|
thumbhash?: string;
|
||||||
// Motion photo (Live Photo) clip. A separate, hidden Immich asset; the same
|
// Motion photo (Live Photo) clip: a hidden asset authorised by the same key
|
||||||
// shared-link key authorises it (Immich's checkSharedLinkAccess whitelists
|
|
||||||
// each shared asset's livePhotoVideoId alongside the asset itself).
|
|
||||||
livePhotoVideoId?: string;
|
livePhotoVideoId?: string;
|
||||||
// True for album assets enumerated via the timeline API, which give us only
|
// True for album assets enumerated via the timeline API, which give us only
|
||||||
// grid fields (id, type, ratio, thumbhash, isTrashed, fileCreatedAt). Their
|
// grid fields (id, type, ratio, thumbhash, isTrashed, fileCreatedAt). Their
|
||||||
|
|||||||
@@ -6,13 +6,9 @@ import { findMotionPhotoStill } from '../src/share'
|
|||||||
import { gallery } from '../src/gallery/builder'
|
import { gallery } from '../src/gallery/builder'
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Motion photo (Live Photo) support. Two rules worth pinning down: the set of
|
Motion photos: clip ids stay bounded by the share's own assets, and
|
||||||
clip ids the video route will serve stays bounded by the share's own assets,
|
`motionUrl` is emitted only for images with a clip while `ipp.motionPhotos`
|
||||||
and `motionUrl` reaches the client only for images that have a clip, and only
|
is on. Config is mocked per test rather than loaded from a file.
|
||||||
while `ipp.motionPhotos` is on.
|
|
||||||
|
|
||||||
The builder reads config through config/access, so mock that module and set
|
|
||||||
options per test rather than loading a real config file.
|
|
||||||
*/
|
*/
|
||||||
const cfg: Record<string, unknown> = {}
|
const cfg: Record<string, unknown> = {}
|
||||||
vi.mock('../src/config/access', () => ({
|
vi.mock('../src/config/access', () => ({
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ Highest quality the lightbox loads when you zoom in past fit-to-screen.
|
|||||||
|
|
||||||
**Type:** `bool` · **Default:** `true`
|
**Type:** `bool` · **Default:** `true`
|
||||||
|
|
||||||
Show motion photos (Live Photos) - an indicator on the gallery thumbnail, and a toggle in the lightbox that plays the photo's short clip and returns to the still when it ends.
|
Show motion photos (Live Photos) - an indicator on the gallery thumbnail, and a toggle in the lightbox that plays the photo's short clip and returns to the still when it ends. The toggle stays on: each motion photo the visitor moves to plays its clip automatically until they switch it off.
|
||||||
|
|
||||||
The clip is only fetched when a visitor presses the toggle, so leaving this on costs no extra bandwidth for visitors who never use it. Set to `false` to serve motion photos as plain stills:
|
Clips are only fetched while the toggle is on, so leaving this on costs no extra bandwidth for visitors who never use it. Set to `false` to serve motion photos as plain stills:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user