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
+29 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
import { detectSupportedMimeType } from './mime'
import { detectSupportedMimeType, getProxyType } from './mime'
describe('detectSupportedMimeType', () => {
it('should detect JPEG', () => {
@@ -39,3 +39,31 @@ describe('detectSupportedMimeType', () => {
expect(detectSupportedMimeType(buffer)).toBeNull()
})
})
describe('getProxyType', () => {
it('should detect image proxyType', () => {
expect(getProxyType('image/png', 'test.png')).toBe('image')
expect(getProxyType('image/jpeg', 'photo.jpg')).toBe('image')
})
it('should detect video proxyType', () => {
expect(getProxyType('video/mp4', 'clip.mp4')).toBe('video')
})
it('should detect audio proxyType', () => {
expect(getProxyType('audio/mpeg', 'song.mp3')).toBe('audio')
})
it('should detect pdf proxyType for pdf, csv, txt, and doc files', () => {
expect(getProxyType('application/pdf', 'doc.pdf')).toBe('pdf')
expect(getProxyType('text/plain', 'notes.txt')).toBe('pdf')
expect(getProxyType('text/csv', 'data.csv')).toBe('pdf')
expect(getProxyType('application/msword', 'letter.doc')).toBe('pdf')
expect(getProxyType(null, 'file.txt')).toBe('pdf')
})
it('should return null for unsupported files', () => {
expect(getProxyType('application/zip', 'archive.zip')).toBeNull()
expect(getProxyType(null, 'unknown.bin')).toBeNull()
})
})