mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 19:04:23 +00:00
feat(file-browser): show video duration on file card preview
Display the video duration (mm:ss) in the bottom-right corner of the video file card preview area with white text and a transparent background. Duration is sourced from media metadata and exposed via the preview DTO. The overlay is gated behind a showDuration prop so it only appears on file cards, not folder card child previews.
This commit is contained in:
@@ -276,7 +276,7 @@ export function FileCard({
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<FilePreview item={displayItem} />
|
||||
<FilePreview item={displayItem} showDuration />
|
||||
)}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { File, Folder } from 'lucide-react'
|
||||
import { SpriteScrubber } from '../sprite-scrubber'
|
||||
import { formatTime } from '../viewers/utils'
|
||||
|
||||
type FilePreviewItem = {
|
||||
type?: string | null
|
||||
@@ -9,39 +10,56 @@ type FilePreviewItem = {
|
||||
thumbnailUrl?: string
|
||||
originalWidth?: number
|
||||
originalHeight?: number
|
||||
duration?: number
|
||||
} | null
|
||||
}
|
||||
|
||||
interface FilePreviewProps {
|
||||
item: FilePreviewItem
|
||||
showDuration?: boolean
|
||||
}
|
||||
|
||||
export const FilePreview = ({ item }: FilePreviewProps) => {
|
||||
export const FilePreview = ({ item, showDuration = false }: FilePreviewProps) => {
|
||||
const isVideo = item.preview?.mediaType?.startsWith('video/')
|
||||
const duration = item.preview?.duration
|
||||
const durationOverlay =
|
||||
showDuration && isVideo && typeof duration === 'number' && duration > 0 ? (
|
||||
<span className="pointer-events-none absolute bottom-1 right-1 text-xs font-medium tabular-nums text-white">
|
||||
{formatTime(duration)}
|
||||
</span>
|
||||
) : null
|
||||
|
||||
const isVideoWithSprite =
|
||||
item.preview?.mediaType?.startsWith('video/') &&
|
||||
item.preview.spriteUrl &&
|
||||
isVideo &&
|
||||
item.preview?.spriteUrl &&
|
||||
item.preview.thumbnailUrl &&
|
||||
item.preview.originalWidth &&
|
||||
item.preview.originalHeight
|
||||
|
||||
if (isVideoWithSprite && item.preview) {
|
||||
return (
|
||||
<SpriteScrubber
|
||||
spriteUrl={item.preview.spriteUrl!}
|
||||
thumbnailUrl={item.preview.thumbnailUrl!}
|
||||
videoWidth={item.preview.originalWidth!}
|
||||
videoHeight={item.preview.originalHeight!}
|
||||
/>
|
||||
<>
|
||||
<SpriteScrubber
|
||||
spriteUrl={item.preview.spriteUrl!}
|
||||
thumbnailUrl={item.preview.thumbnailUrl!}
|
||||
videoWidth={item.preview.originalWidth!}
|
||||
videoHeight={item.preview.originalHeight!}
|
||||
/>
|
||||
{durationOverlay}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
if (item.preview?.thumbnailUrl) {
|
||||
return (
|
||||
<img
|
||||
src={item.preview.thumbnailUrl}
|
||||
alt="Preview"
|
||||
className="w-full h-full object-contain bg-black"
|
||||
/>
|
||||
<>
|
||||
<img
|
||||
src={item.preview.thumbnailUrl}
|
||||
alt="Preview"
|
||||
className="w-full h-full object-contain bg-black"
|
||||
/>
|
||||
{durationOverlay}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user