feat(asset): replace mediaType/mimeType logic with proxyType

This commit is contained in:
yiling
2026-07-20 10:22:36 +08:00
parent c45a1d9ee9
commit f158d04686
40 changed files with 219 additions and 119 deletions
@@ -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'
}