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
+37
View File
@@ -1,3 +1,40 @@
export type ProxyType = 'image' | 'video' | 'audio' | 'pdf'
export function getProxyType(
mediaType?: string | null,
filename?: string | null,
): ProxyType | null {
const lowerMediaType = mediaType?.toLowerCase() || ''
const lowerFilename = filename?.toLowerCase() || ''
if (lowerMediaType.startsWith('image/')) return 'image'
if (lowerMediaType.startsWith('video/')) return 'video'
if (lowerMediaType.startsWith('audio/')) return 'audio'
if (
lowerMediaType === 'application/pdf' ||
lowerMediaType === 'text/plain' ||
lowerMediaType === 'text/csv' ||
lowerMediaType.includes('msword') ||
lowerMediaType.includes('officedocument') ||
lowerMediaType.includes('vnd.ms-') ||
lowerMediaType.startsWith('text/') ||
lowerFilename.endsWith('.pdf') ||
lowerFilename.endsWith('.txt') ||
lowerFilename.endsWith('.csv') ||
lowerFilename.endsWith('.doc') ||
lowerFilename.endsWith('.docx') ||
lowerFilename.endsWith('.xls') ||
lowerFilename.endsWith('.xlsx') ||
lowerFilename.endsWith('.ppt') ||
lowerFilename.endsWith('.pptx')
) {
return 'pdf'
}
return null
}
const PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]
export function detectSupportedMimeType(buffer: Uint8Array): string | null {