feat(transcode): add PSD support via ImageMagick and enforce sRGB conversion

This commit is contained in:
yiling
2026-07-23 16:19:25 +08:00
parent 21de21902e
commit 8d1c51abca
12 changed files with 277 additions and 64 deletions
+7
View File
@@ -27,6 +27,11 @@ describe('detectSupportedMimeType', () => {
expect(detectSupportedMimeType(buffer)).toBe('image/webp')
})
it('should detect PSD', () => {
const buffer = new Uint8Array([0x38, 0x42, 0x50, 0x53, 0x00, 0x01])
expect(detectSupportedMimeType(buffer)).toBe('image/vnd.adobe.photoshop')
})
it('should detect MP4', () => {
const buffer = new Uint8Array([
0x00, 0x00, 0x00, 0x18, 0x66, 0x74, 0x79, 0x70, 0x69, 0x73, 0x6f, 0x6d,
@@ -44,6 +49,8 @@ describe('getProxyType', () => {
it('should detect image proxyType', () => {
expect(getProxyType('image/png', 'test.png')).toBe('image')
expect(getProxyType('image/jpeg', 'photo.jpg')).toBe('image')
expect(getProxyType('image/vnd.adobe.photoshop', 'design.psd')).toBe('image')
expect(getProxyType(null, 'design.psd')).toBe('image')
})
it('should detect video proxyType', () => {
+4 -1
View File
@@ -7,7 +7,7 @@ export function getProxyType(
const lowerMediaType = mediaType?.toLowerCase() || ''
const lowerFilename = filename?.toLowerCase() || ''
if (lowerMediaType.startsWith('image/')) return 'image'
if (lowerMediaType.startsWith('image/') || lowerFilename.endsWith('.psd')) return 'image'
if (lowerMediaType.startsWith('video/')) return 'video'
if (lowerMediaType.startsWith('audio/')) return 'audio'
@@ -32,6 +32,9 @@ export function getProxyType(
const PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]
export function detectSupportedMimeType(buffer: Uint8Array): string | null {
if (startsWithAscii(buffer, 0, '8BPS')) {
return 'image/vnd.adobe.photoshop'
}
if (startsWith(buffer, [0xff, 0xd8, 0xff])) {
return buffer[3] === 0xf7 ? null : 'image/jpeg'
}