mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 10:55:27 +00:00
feat(asset): replace mediaType/mimeType logic with proxyType
This commit is contained in:
@@ -51,6 +51,7 @@ interface BreadcrumbNavProps {
|
||||
type: 'file' | 'folder'
|
||||
version?: number
|
||||
mediaType?: string | null
|
||||
proxyType?: 'image' | 'video' | 'audio' | 'pdf' | null
|
||||
}
|
||||
isRootFolder: boolean
|
||||
displayStyle?: 'card' | 'list'
|
||||
@@ -158,7 +159,7 @@ export function BreadcrumbNav({
|
||||
}
|
||||
}
|
||||
|
||||
const isAudio = currentAsset.mediaType?.startsWith('audio/')
|
||||
const isAudio = currentAsset.proxyType === 'audio'
|
||||
const hasVideoTranscodes =
|
||||
!isAudio &&
|
||||
downloadInfo?.videoTranscodes &&
|
||||
|
||||
@@ -346,7 +346,7 @@ export const MessageCard: React.FC<MessageCardProps> = ({
|
||||
{message.attachments && message.attachments.length > 0 && (
|
||||
<div className="flex flex-wrap gap-2 mt-3">
|
||||
{message.attachments.map((att) => {
|
||||
const isImage = att.mediaType?.startsWith('image/')
|
||||
const isImage = att.proxyType === 'image'
|
||||
const name = att.url?.split('/').pop()?.split('?')[0] || 'file'
|
||||
return (
|
||||
<div
|
||||
|
||||
@@ -4,19 +4,19 @@ import { kindOf, pickDefaultCompareVersions, clampFrame, isSameType } from './co
|
||||
describe('compare-utils', () => {
|
||||
describe('kindOf', () => {
|
||||
it('classifies image media types', () => {
|
||||
expect(kindOf('image/png')).toBe('image')
|
||||
expect(kindOf('image/webp')).toBe('image')
|
||||
expect(kindOf('image')).toBe('image')
|
||||
expect(kindOf({ proxyType: 'image' })).toBe('image')
|
||||
})
|
||||
|
||||
it('classifies video media types', () => {
|
||||
expect(kindOf('video/mp4')).toBe('video')
|
||||
expect(kindOf('video/quicktime')).toBe('video')
|
||||
expect(kindOf('video')).toBe('video')
|
||||
expect(kindOf({ proxyType: 'video' })).toBe('video')
|
||||
})
|
||||
|
||||
it('returns unsupported for missing or unknown types', () => {
|
||||
expect(kindOf(null)).toBe('unsupported')
|
||||
expect(kindOf(undefined)).toBe('unsupported')
|
||||
expect(kindOf('application/pdf')).toBe('unsupported')
|
||||
expect(kindOf('pdf')).toBe('unsupported')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import type { PaneKind } from './types'
|
||||
|
||||
/** Classify an asset's media type into a compare pane kind. */
|
||||
export function kindOf(mediaType: string | null | undefined): PaneKind {
|
||||
if (!mediaType) return 'unsupported'
|
||||
if (mediaType.startsWith('image/')) return 'image'
|
||||
if (mediaType.startsWith('video/')) return 'video'
|
||||
export function kindOf(item: { proxyType?: string | null } | string | null | undefined): PaneKind {
|
||||
if (!item) return 'unsupported'
|
||||
const proxyType = typeof item === 'object' ? item.proxyType : item
|
||||
if (proxyType === 'image') return 'image'
|
||||
if (proxyType === 'video') return 'video'
|
||||
return 'unsupported'
|
||||
}
|
||||
|
||||
|
||||
@@ -214,8 +214,7 @@ export function FileListItem({
|
||||
alt=""
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
) : displayItem.preview?.mediaType?.startsWith('audio/') ||
|
||||
displayItem.mediaType?.startsWith('audio/') ? (
|
||||
) : displayItem.preview?.proxyType === 'audio' || displayItem.proxyType === 'audio' ? (
|
||||
<AudioLines className="h-4 w-4 text-muted-foreground" />
|
||||
) : displayItem.type === 'folder' ? (
|
||||
<Folder className="h-4 w-4 text-primary" />
|
||||
|
||||
@@ -22,8 +22,7 @@ export const CarouselFilePreview = ({ item }: { item: AssetInfo }) => {
|
||||
)
|
||||
}
|
||||
|
||||
const isAudio =
|
||||
item.preview?.mediaType?.startsWith('audio/') || item.mediaType?.startsWith('audio/')
|
||||
const isAudio = item.preview?.proxyType === 'audio' || item.proxyType === 'audio'
|
||||
if (isAudio) {
|
||||
return (
|
||||
<div className="w-full h-full flex items-center justify-center bg-muted">
|
||||
|
||||
@@ -315,7 +315,7 @@ export function FileViewerRightSidebar({
|
||||
return (
|
||||
<div className="bg-background h-full flex flex-col overflow-hidden">
|
||||
{/* Lightbox */}
|
||||
{viewingAttachment && viewingAttachment.mediaType?.startsWith('image/') && (
|
||||
{viewingAttachment && viewingAttachment.proxyType === 'image' && (
|
||||
<div
|
||||
className="fixed inset-0 z-[100] bg-black/95 flex flex-col items-center justify-center p-4 animate-in fade-in duration-200"
|
||||
onClick={() => setViewingAttachment(null)}
|
||||
|
||||
@@ -92,14 +92,13 @@ export const NotificationCard = ({ notification }: NotificationCardProps) => {
|
||||
})()
|
||||
|
||||
const isVideoWithSprite =
|
||||
asset?.mediaType?.startsWith('video/') &&
|
||||
asset?.proxyType === 'video' &&
|
||||
asset.preview &&
|
||||
asset.thumbnailUrl &&
|
||||
asset.originalWidth &&
|
||||
asset.originalHeight
|
||||
|
||||
const hasPreview =
|
||||
asset?.preview && (asset.mediaType?.startsWith('image') || asset.mediaType?.startsWith('video'))
|
||||
const hasPreview = asset?.preview && (asset.proxyType === 'image' || asset.proxyType === 'video')
|
||||
|
||||
return (
|
||||
<div className="flex py-2 cursor-pointer group border border-transparent items-center justify-center">
|
||||
|
||||
@@ -647,10 +647,9 @@ export function PublicShareManager({
|
||||
mediaControllerRef.current?.pause()
|
||||
}}
|
||||
selectedCommentId={selectedCommentId}
|
||||
hideAnnotationControl={(isCompareMode
|
||||
? compareActiveAsset
|
||||
: currentSelectedItem
|
||||
)?.mediaType?.startsWith('audio/')}
|
||||
hideAnnotationControl={
|
||||
(isCompareMode ? compareActiveAsset : currentSelectedItem)?.proxyType === 'audio'
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -118,7 +118,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
const [currentResolution, setCurrentResolution] = useState(initialRes?.resolution ?? 'Original')
|
||||
const currentSrcRef = useRef(initialRes?.url)
|
||||
|
||||
const isAudio = file.mediaType?.startsWith('audio/')
|
||||
const isAudio = file.proxyType === 'audio'
|
||||
const { currentFrame, seekToFrame } = useFramePlayer(videoRef, frameRate, totalFrames, isAudio)
|
||||
|
||||
const zoomRef = useRef(zoom)
|
||||
@@ -440,7 +440,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
>
|
||||
<div ref={videoContainerRef} className="absolute inset-0 z-[-1]" />
|
||||
|
||||
{file.mediaType?.startsWith('audio/') ? (
|
||||
{isAudio ? (
|
||||
<div className="flex flex-col items-center justify-center text-muted-foreground w-full h-full pointer-events-none select-none">
|
||||
<AudioLines
|
||||
className={cn(
|
||||
|
||||
@@ -114,7 +114,7 @@ export const VideoControlBar: React.FC<ControlBarProps> = ({
|
||||
// fullscreen). Compare keeps it in-flow. Colors stay theme-aware either way.
|
||||
const overlay = state.isFullScreen && floatOverlayInFullScreen
|
||||
|
||||
const isAudio = data.mediaType?.startsWith('audio/')
|
||||
const isAudio = data.proxyType === 'audio'
|
||||
const previewResolutions = resolutions.filter((r) => !r.isRaw)
|
||||
|
||||
const startTimecode = data.media?.metadata?.startTimecode
|
||||
|
||||
@@ -194,7 +194,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
const dbTotalFrames = metadata?.totalFrames || 0
|
||||
const containerDuration = metadata?.duration || 0
|
||||
|
||||
const isAudio = data.mediaType?.startsWith('audio/')
|
||||
const isAudio = data.proxyType === 'audio'
|
||||
const totalFrames = resolveTotalFrames({ dbTotalFrames, containerDuration, frameRate })
|
||||
const { currentFrame, seekToFrame } = useFramePlayer(videoRef, frameRate, totalFrames, isAudio)
|
||||
|
||||
@@ -626,7 +626,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
{/* Hidden VideoJS container */}
|
||||
<div ref={videoContainerRef} className="absolute inset-0 z-[-1]" />
|
||||
|
||||
{data.mediaType?.startsWith('audio/') ? (
|
||||
{isAudio ? (
|
||||
<div className="flex flex-col items-center justify-center text-muted-foreground w-full h-full pointer-events-none select-none">
|
||||
<AudioLines
|
||||
className={cn(
|
||||
|
||||
Reference in New Issue
Block a user