Files
shumai/packages/webui/components/file-browser/file-preview.tsx
T
Yiling-J 43a2eced75 feat(transcode): add 3D asset support and turntable viewer (#454)
* feat(transcode): add 3D asset support and turntable viewer

* perf(turntable): stream file via Bun.file and increase upload timeout

* feat(turntable): increase upload timeout to 15m to support 5GB uploads

* fix(webui): align 3D model viewer layout and full-width control bar with video viewer

* feat(webui): unify 3D viewer bottom bar and redesign cyclic ruler slider

- Place RulerSlider in single row with playback and zoom controls, centered with max 320px width
- Flank RulerSlider with minus and plus buttons to step angle by 15°
- Redesign RulerSlider with fixed center indicator and moving cyclic track with continuous 360° wrapping
- Render major ticks longer at 60° intervals without numeric text labels on track
- Display floating degree tooltip above center indicator only during dragging

* fix(webui): prevent RulerSlider from collapsing to 0px width in control bar

- Use flex layout with flex-1 on left and right clusters to preserve center cluster width
- Enforce min-w-[140px] and w-full on RulerSlider
- Fix tooltip positioning and remove outer overflow-hidden

* feat(webui): snap RulerSlider track directly to discrete 15° ticks during drag

* fix(webui): prevent ruler snap-back caused by floating point second truncation

- Use Math.round instead of Math.floor in secondToDegree to avoid 0.999996 dropping to previous frame
- Ensure final dragDegree is committed on pointer up

* fix(webui): fix arrow key frame rounding and duplicate event bubbling

- Use Math.round instead of Math.floor for keyboard arrow frame navigation in ModelViewer
- Add e.stopPropagation() to RulerSlider keyboard events to prevent duplicate bubbling to window listener

* feat(webui): redesign RulerSlider with encapsulated step buttons and capsule pill track

* feat(webui): make RulerSlider responsive on mobile and remove bottom bar reset button

* fix(webui): load 3d video directly without poster and invert drag rotation to counterclockwise

* fix(webui): fix 3d asset viewer frame seeking and drag jitter

* feat(transcode): show 3D asset poster preview immediately after render start

* fix(viewer): synchronize 3D turntable playback via frame callback to prevent skipped degrees

* fix(viewer): handle touchpad zoom gestures and prevent page zoom in 3D viewer

* fix(viewer): eliminate 3D model rotation jitter at 345 degrees

* fix(share): watermark 3D asset turntable video on share links

* fix(share): preserve video transcode resolution on watermarked share links

* fix(viewer): download original 3D model file instead of rendered turntable MP4
2026-10-11 21:32:28 +08:00

106 lines
3.0 KiB
TypeScript

import { File, Folder, AudioLines } from 'lucide-react'
import { SpriteScrubber } from '../sprite-scrubber'
import { formatTime } from '../viewers/video/utils'
type FilePreviewItem = {
type?: string | null
proxyType?: 'image' | 'video' | 'audio' | 'pdf' | '3d' | null
preview?: {
mediaType?: string | null
proxyType?: 'image' | 'video' | 'audio' | 'pdf' | '3d' | null
spriteUrl?: string
thumbnailUrl?: string
originalWidth?: number
originalHeight?: number
duration?: number
pageCount?: number
} | null
}
interface FilePreviewProps {
item: FilePreviewItem
showDuration?: boolean
}
export const FilePreview = ({ item, showDuration = false }: FilePreviewProps) => {
const proxyType = item.preview?.proxyType || item.proxyType
const isVideo = proxyType === 'video'
const isAudio = proxyType === 'audio'
const isPdf = proxyType === 'pdf'
const is3D = proxyType === '3d'
const hasDuration = isVideo || isAudio
const duration = item.preview?.duration
const pageCount = item.preview?.pageCount
const overlay =
showDuration && hasDuration && typeof duration === 'number' && duration > 0 ? (
<span className="pointer-events-none absolute bottom-1 right-1 rounded bg-black/60 px-1 py-0.5 text-xs font-medium tabular-nums text-white">
{formatTime(duration)}
</span>
) : showDuration && isPdf && typeof pageCount === 'number' && pageCount > 0 ? (
<span className="pointer-events-none absolute bottom-1 right-1 rounded bg-black/60 px-1 py-0.5 text-xs font-medium tabular-nums text-white">
{pageCount} P
</span>
) : null
const isMediaWithSprite =
(isVideo || isPdf || is3D) &&
item.preview?.spriteUrl &&
item.preview.thumbnailUrl &&
item.preview.originalWidth &&
item.preview.originalHeight
if (isMediaWithSprite && item.preview) {
return (
<>
<SpriteScrubber
spriteUrl={item.preview.spriteUrl!}
thumbnailUrl={item.preview.thumbnailUrl!}
videoWidth={item.preview.originalWidth!}
videoHeight={item.preview.originalHeight!}
/>
{overlay}
</>
)
}
if (item.preview?.thumbnailUrl) {
return (
<>
<img
src={item.preview.thumbnailUrl}
alt="Preview"
className="w-full h-full object-contain bg-black"
/>
{overlay}
</>
)
}
if (isAudio) {
return (
<>
<div className="w-full h-full flex items-center justify-center bg-zinc-950">
<AudioLines className="w-8 h-8 text-zinc-500" />
</div>
{overlay}
</>
)
}
// Assumption: folders in latestChildren have no media type.
if (!item.type) {
return (
<div className="w-full h-full flex items-center justify-center bg-linear-to-t from-black/5 to-black/0">
<Folder className="w-8 h-8 fill-primary/60 stroke-0" />
</div>
)
}
return (
<div className="w-full h-full flex items-center justify-center">
<File className="w-8 h-8 fill-primary/60 stroke-0" />
</div>
)
}