feat(webui): add space key quick preview for files and folders (#402)

* feat(webui): add space key quick preview for files and folders

Allow users in file list views to press the Space key to quick preview the most recently selected item.

- Add FilePreviewDialog supporting both folder previews (icon, name, count) and real file previews (reusing FileViewer with viewer area and control bar).
- Constrain dialog to max 1920x1080 or 70vw/70vh.
- Support dismissing via close button, clicking outside, or pressing Space again (intercepted in capture phase).
- Enable across project file lists, share links, and public share views.

* feat(webui): auto play video in quick preview dialog

- Pass autoPlay prop from FilePreviewDialog through FileViewer to VideoViewer
- Configure videojs with autoplay: 'any' and handle policy rejection with muted autoplay fallback
- Add test coverage for autoPlay prop forwarding in FilePreviewDialog

* fix(webui): resolve video quick preview initialization and autoplay pause bugs

* fix(webui): support folder symlinks and password-protected shares in quick preview
This commit is contained in:
Yiling-J
2026-09-13 18:51:06 +08:00
committed by GitHub
parent c5b57ca862
commit 87e88396d1
13 changed files with 779 additions and 27 deletions
@@ -21,6 +21,7 @@ export interface FileViewerProps {
shareId?: string
/** When false, the viewer hides its download affordances. Defaults to true. */
allowDownload?: boolean
autoPlay?: boolean
children?: React.ReactNode
}
@@ -119,4 +119,67 @@ describe('VideoViewer', () => {
}),
)
})
it('initializes VideoJS when transcode URL becomes available after initially empty with same ID', () => {
const initialVideo: AssetInfo = {
id: 'video-pending',
name: 'pending.mp4',
proxyType: 'video',
media: {
metadata: {
originalWidth: 1920,
originalHeight: 1080,
duration: 10,
frameRate: 30,
totalFrames: 300,
},
videoTranscodes: [
{
resolution: '1080p',
// URL not yet presigned (e.g. from file list payload)
url: undefined as unknown as string,
width: 1920,
height: 1080,
},
],
},
} as unknown as AssetInfo
const detailedVideo: AssetInfo = {
...initialVideo,
media: {
...initialVideo.media,
videoTranscodes: [
{
resolution: '1080p',
url: 'https://cdn.example.com/signed-pending-1080p.mp4',
width: 1920,
height: 1080,
},
],
},
} as unknown as AssetInfo
const { rerender } = render(<VideoViewer file={initialVideo} autoPlay={true} />)
// Initially targetSrc is empty, videojs should not be initialized
expect(videojsMock).not.toHaveBeenCalled()
// Rerender with detailedVideo (same id, but signed URL now available)
rerender(<VideoViewer file={detailedVideo} autoPlay={true} />)
// VideoJS should now be initialized with the new URL
expect(videojsMock).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
autoplay: false,
sources: [
{
src: 'https://cdn.example.com/signed-pending-1080p.mp4',
type: 'video/mp4',
},
],
}),
)
})
})
@@ -27,6 +27,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
shareId,
children,
allowDownload,
autoPlay,
},
ref,
) => {
@@ -144,7 +145,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
setIsPlayerReady(false)
setBuffered(0)
lastProcessedStartTimeRef.current = null
}, [data.id])
}, [data.id, Boolean(initialRes?.url)])
const vidW = data.media?.metadata?.originalWidth || 1920
const vidH = data.media?.metadata?.originalHeight || 1080
@@ -304,6 +305,30 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
],
}))
if (autoPlay) {
const startAutoPlay = () => {
if (player.isDisposed()) return
const playPromise = player.play()
if (playPromise !== undefined) {
playPromise.catch(() => {
if (player.isDisposed()) return
player.muted(true)
setState((prev) => ({ ...prev, isMuted: true }))
player.play()?.catch(() => {})
})
}
}
player.ready(() => {
if (player.isDisposed()) return
if (player.readyState() >= 2) {
startAutoPlay()
} else {
player.one('canplay', startAutoPlay)
}
})
}
// Extract video element for Konva
const htmlVid = videoElement.querySelector('video')
if (htmlVid) {
@@ -378,7 +403,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
videoRef.current = null
}
}
}, [data.id])
}, [data.id, Boolean(initialRes?.url), autoPlay])
// Handle changes to startTime (e.g., clicking different chunks in search results)
useEffect(() => {