mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 08:26:35 +00:00
feat(transcode): add initial camera RAW image support (#435)
- Add centralized RAW file extension set and detection helper for 23 common camera RAW formats - Update getProxyType and EXTENSION_MIME_TYPES to route RAW formats into the image pipeline - Add exiftool-vendored runtime dependency and mark as external in build-npm script - Implement embedded JPEG extraction to temporary file with priority JpgFromRaw2 -> JpgFromRaw -> PreviewImage - Read and apply EXIF orientation from RAW container to prevent rotation/mirroring issues - Integrate into TranscodeService.getImageInfo and transcodeImage with proper temporary file cleanup - Add hasUsablePreview guard in transcodeImageWorkflow to gracefully handle RAW files without embedded previews - Add unit, service, workflow, and E2E tests for RAW processing
This commit is contained in:
@@ -15,6 +15,30 @@ const EXTENSION_MIME_TYPES: Record<string, string> = {
|
||||
'.txt': 'text/plain',
|
||||
'.md': 'text/markdown',
|
||||
'.markdown': 'text/markdown',
|
||||
// Camera RAW formats
|
||||
'.3fr': 'image/x-hasselblad-3fr',
|
||||
'.arw': 'image/x-sony-arw',
|
||||
'.cr2': 'image/x-canon-cr2',
|
||||
'.cr3': 'image/x-canon-cr3',
|
||||
'.crw': 'image/x-canon-crw',
|
||||
'.dcr': 'image/x-kodak-dcr',
|
||||
'.dng': 'image/x-adobe-dng',
|
||||
'.erf': 'image/x-epson-erf',
|
||||
'.fff': 'image/x-hasselblad-fff',
|
||||
'.iiq': 'image/x-phaseone-iiq',
|
||||
'.kdc': 'image/x-kodak-kdc',
|
||||
'.nef': 'image/x-nikon-nef',
|
||||
'.nrw': 'image/x-nikon-nrw',
|
||||
'.orf': 'image/x-olympus-orf',
|
||||
'.pef': 'image/x-pentax-pef',
|
||||
'.raf': 'image/x-fuji-raf',
|
||||
'.raw': 'image/x-panasonic-raw',
|
||||
'.rw2': 'image/x-panasonic-rw2',
|
||||
'.rwl': 'image/x-leica-rwl',
|
||||
'.sr2': 'image/x-sony-sr2',
|
||||
'.srf': 'image/x-sony-srf',
|
||||
'.srw': 'image/x-samsung-srw',
|
||||
'.x3f': 'image/x-sigma-x3f',
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -92,6 +92,20 @@ describe('getProxyType', () => {
|
||||
expect(getProxyType(null, 'design.psd')).toBe('image')
|
||||
})
|
||||
|
||||
it('should detect image proxyType for RAW camera files', () => {
|
||||
// RAW files typically upload with application/octet-stream or null mediaType
|
||||
expect(getProxyType('application/octet-stream', 'photo.cr2')).toBe('image')
|
||||
expect(getProxyType('application/octet-stream', 'photo.arw')).toBe('image')
|
||||
expect(getProxyType(null, 'photo.dng')).toBe('image')
|
||||
expect(getProxyType(null, 'photo.nef')).toBe('image')
|
||||
expect(getProxyType(null, 'photo.raf')).toBe('image')
|
||||
expect(getProxyType(null, 'photo.cr3')).toBe('image')
|
||||
expect(getProxyType(null, 'photo.rw2')).toBe('image')
|
||||
// Case-insensitive
|
||||
expect(getProxyType(null, 'PHOTO.ARW')).toBe('image')
|
||||
expect(getProxyType(null, 'Photo.DNG')).toBe('image')
|
||||
})
|
||||
|
||||
it('should detect video proxyType', () => {
|
||||
expect(getProxyType('video/mp4', 'clip.mp4')).toBe('video')
|
||||
})
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { isRawImage } from './raw'
|
||||
|
||||
export type ProxyType = 'image' | 'video' | 'audio' | 'pdf'
|
||||
|
||||
export function isOfficeDocument(mediaType?: string | null, filename?: string | null): boolean {
|
||||
@@ -73,7 +75,12 @@ export function getProxyType(
|
||||
const lowerMediaType = mediaType?.toLowerCase() || ''
|
||||
const lowerFilename = filename?.toLowerCase() || ''
|
||||
|
||||
if (lowerMediaType.startsWith('image/') || lowerFilename.endsWith('.psd')) return 'image'
|
||||
if (
|
||||
lowerMediaType.startsWith('image/') ||
|
||||
lowerFilename.endsWith('.psd') ||
|
||||
isRawImage(lowerFilename)
|
||||
)
|
||||
return 'image'
|
||||
if (lowerMediaType.startsWith('video/')) return 'video'
|
||||
if (lowerMediaType.startsWith('audio/')) return 'audio'
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { isRawImage } from './raw'
|
||||
|
||||
describe('isRawImage', () => {
|
||||
it('recognizes common RAW extensions (lowercase)', () => {
|
||||
expect(isRawImage('photo.cr2')).toBe(true)
|
||||
expect(isRawImage('photo.arw')).toBe(true)
|
||||
expect(isRawImage('photo.dng')).toBe(true)
|
||||
expect(isRawImage('photo.nef')).toBe(true)
|
||||
expect(isRawImage('photo.raf')).toBe(true)
|
||||
expect(isRawImage('photo.rw2')).toBe(true)
|
||||
expect(isRawImage('photo.orf')).toBe(true)
|
||||
expect(isRawImage('photo.pef')).toBe(true)
|
||||
expect(isRawImage('photo.cr3')).toBe(true)
|
||||
expect(isRawImage('photo.x3f')).toBe(true)
|
||||
expect(isRawImage('photo.raw')).toBe(true)
|
||||
expect(isRawImage('photo.3fr')).toBe(true)
|
||||
expect(isRawImage('photo.iiq')).toBe(true)
|
||||
expect(isRawImage('photo.kdc')).toBe(true)
|
||||
expect(isRawImage('photo.dcr')).toBe(true)
|
||||
expect(isRawImage('photo.erf')).toBe(true)
|
||||
expect(isRawImage('photo.fff')).toBe(true)
|
||||
expect(isRawImage('photo.crw')).toBe(true)
|
||||
expect(isRawImage('photo.nrw')).toBe(true)
|
||||
expect(isRawImage('photo.rwl')).toBe(true)
|
||||
expect(isRawImage('photo.sr2')).toBe(true)
|
||||
expect(isRawImage('photo.srf')).toBe(true)
|
||||
expect(isRawImage('photo.srw')).toBe(true)
|
||||
})
|
||||
|
||||
it('recognizes RAW extensions case-insensitively', () => {
|
||||
expect(isRawImage('photo.CR2')).toBe(true)
|
||||
expect(isRawImage('IMG_1234.ARW')).toBe(true)
|
||||
expect(isRawImage('test.DNG')).toBe(true)
|
||||
expect(isRawImage('photo.Nef')).toBe(true)
|
||||
})
|
||||
|
||||
it('rejects non-RAW image files', () => {
|
||||
expect(isRawImage('photo.jpg')).toBe(false)
|
||||
expect(isRawImage('photo.png')).toBe(false)
|
||||
expect(isRawImage('photo.webp')).toBe(false)
|
||||
expect(isRawImage('photo.gif')).toBe(false)
|
||||
expect(isRawImage('photo.svg')).toBe(false)
|
||||
})
|
||||
|
||||
it('rejects non-image files', () => {
|
||||
expect(isRawImage('design.psd')).toBe(false)
|
||||
expect(isRawImage('video.mp4')).toBe(false)
|
||||
expect(isRawImage('doc.pdf')).toBe(false)
|
||||
expect(isRawImage('readme.txt')).toBe(false)
|
||||
})
|
||||
|
||||
it('rejects files without extensions', () => {
|
||||
expect(isRawImage('photo')).toBe(false)
|
||||
expect(isRawImage('rawfile')).toBe(false)
|
||||
})
|
||||
|
||||
it('handles filenames with multiple dots', () => {
|
||||
expect(isRawImage('my.photo.cr2')).toBe(true)
|
||||
expect(isRawImage('backup.2024.dng')).toBe(true)
|
||||
expect(isRawImage('my.photo.jpg')).toBe(false)
|
||||
})
|
||||
|
||||
it('handles paths with directories', () => {
|
||||
expect(isRawImage('/home/user/photos/photo.cr2')).toBe(true)
|
||||
expect(isRawImage('C:\\Users\\photos\\photo.arw')).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Centralized set of recognized camera RAW file extensions.
|
||||
* Used only for routing files into the ExifTool extraction path.
|
||||
*/
|
||||
const RAW_EXTENSIONS: ReadonlySet<string> = new Set([
|
||||
'.3fr',
|
||||
'.arw',
|
||||
'.cr2',
|
||||
'.cr3',
|
||||
'.crw',
|
||||
'.dcr',
|
||||
'.dng',
|
||||
'.erf',
|
||||
'.fff',
|
||||
'.iiq',
|
||||
'.kdc',
|
||||
'.nef',
|
||||
'.nrw',
|
||||
'.orf',
|
||||
'.pef',
|
||||
'.raf',
|
||||
'.raw',
|
||||
'.rw2',
|
||||
'.rwl',
|
||||
'.sr2',
|
||||
'.srf',
|
||||
'.srw',
|
||||
'.x3f',
|
||||
])
|
||||
|
||||
/** Check whether a filename has a recognized camera RAW extension. */
|
||||
export function isRawImage(filename: string): boolean {
|
||||
const dotIndex = filename.lastIndexOf('.')
|
||||
if (dotIndex === -1) return false
|
||||
const ext = filename.slice(dotIndex).toLowerCase()
|
||||
return RAW_EXTENSIONS.has(ext)
|
||||
}
|
||||
Reference in New Issue
Block a user