mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-29 20:34:28 +00:00
feat(asset): replace mediaType/mimeType logic with proxyType
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user