Skip to content

High performance self-hosted photo and video management solution.

feat(server/web): Initial support for RAF and SRW RAW formats (#1414)

Skyler Mäntysaari0d543bbb0a7d
diff --git a/server/apps/immich/src/config/asset-upload.config.spec.ts b/server/apps/immich/src/config/asset-upload.config.spec.ts
index 9e76ceb853..f456bbbc55 100644
--- a/server/apps/immich/src/config/asset-upload.config.spec.ts
+++ b/server/apps/immich/src/config/asset-upload.config.spec.ts
@@ -55,7 +55,7 @@ describe('assetUploadOption', () => {
});
it('should allow videos', async () => {
- const file = { mimetype: 'image/mp4', originalname: 'test.mp4' } as any;
+ const file = { mimetype: 'video/mp4', originalname: 'test.mp4' } as any;
fileFilter(mock.userRequest, file, callback);
expect(callback).toHaveBeenCalledWith(null, true);
});
@@ -66,6 +66,18 @@ describe('assetUploadOption', () => {
expect(callback).toHaveBeenCalledWith(null, true);
});
+ it('should allow .raf recognized', () => {
+ const file = { mimetype: 'image/x-fuji-raf', originalname: 'test.raf' } as any;
+ fileFilter(mock.userRequest, file, callback);
+ expect(callback).toHaveBeenCalledWith(null, true);
+ });
+
+ it('should allow .srw recognized', () => {
+ const file = { mimetype: 'image/x-samsung-srw', originalname: 'test.srw' } as any;
+ fileFilter(mock.userRequest, file, callback);
+ expect(callback).toHaveBeenCalledWith(null, true);
+ });
+
it('should not allow unknown types', async () => {
const file = { mimetype: 'application/html', originalname: 'test.html' } as any;
const callback = jest.fn();
diff --git a/server/apps/immich/src/config/asset-upload.config.ts b/server/apps/immich/src/config/asset-upload.config.ts
index 770ffc97d5..2e1faf4e40 100644
--- a/server/apps/immich/src/config/asset-upload.config.ts
+++ b/server/apps/immich/src/config/asset-upload.config.ts
@@ -10,8 +10,6 @@ import sanitize from 'sanitize-filename';
import { AuthUserDto } from '../decorators/auth-user.decorator';
import { patchFormData } from '../utils/path-form-data.util';
-const logger = new Logger('AssetUploadConfig');
-
export interface ImmichFile extends Express.Multer.File {
/** sha1 hash of file */
checksum: Buffer;
@@ -48,13 +46,15 @@ export function customStorage(): StorageEngine {
export const multerUtils = { fileFilter, filename, destination };
+const logger = new Logger('AssetUploadConfig');
+
function fileFilter(req: Request, file: any, cb: any) {
if (!req.user || (req.user.isPublicUser && !req.user.isAllowUpload)) {
return cb(new UnauthorizedException());
}
if (
file.mimetype.match(
- /\/(jpg|jpeg|png|gif|mp4|webm|x-msvideo|quicktime|heic|heif|dng|x-adobe-dng|webp|tiff|3gpp|nef|x-nikon-nef)$/,
+ /\/(jpg|jpeg|png|gif|mp4|webm|x-msvideo|quicktime|heic|heif|dng|x-adobe-dng|webp|tiff|3gpp|nef|x-nikon-nef|x-fuji-raf|x-samsung-srw)$/,
)
) {
cb(null, true);
diff --git a/server/apps/microservices/src/processors/thumbnail.processor.ts b/server/apps/microservices/src/processors/thumbnail.processor.ts
index b1b1928197..14ad30aae1 100644
--- a/server/apps/microservices/src/processors/thumbnail.processor.ts
+++ b/server/apps/microservices/src/processors/thumbnail.processor.ts
@@ -14,6 +14,7 @@ import { Repository } from 'typeorm/repository/Repository';
import { join } from 'path';
import { CommunicationGateway } from 'apps/immich/src/api-v1/communication/communication.gateway';
import { IMachineLearningJob } from '@app/domain';
+import { exiftool } from 'exiftool-vendored';
@Processor(QueueName.THUMBNAIL_GENERATION)
export class ThumbnailGeneratorProcessor {
@@ -53,7 +54,15 @@ export class ThumbnailGeneratorProcessor {
.resize(1440, 1440, { fit: 'outside', withoutEnlargement: true })
.jpeg()
.rotate()
- .toFile(jpegThumbnailPath);
+ .toFile(jpegThumbnailPath)
+ .catch(() => {
+ this.logger.warn(
+ 'Failed to generate jpeg thumbnail for asset: ' +
+ asset.id +
+ ' using sharp, failing over to exiftool-vendored',
+ );
+ return exiftool.extractThumbnail(asset.originalPath, jpegThumbnailPath);
+ });
await this.assetRepository.update({ id: asset.id }, { resizePath: jpegThumbnailPath });
} catch (error: any) {
this.logger.error('Failed to generate jpeg thumbnail for asset: ' + asset.id, error.stack);
diff --git a/web/src/lib/utils/asset-utils.ts b/web/src/lib/utils/asset-utils.ts
index 06642b0a0b..dc13c4f959 100644
--- a/web/src/lib/utils/asset-utils.ts
+++ b/web/src/lib/utils/asset-utils.ts
@@ -141,7 +141,11 @@ export function getFileMimeType(file: File): string {
case '3gp':
return 'video/3gpp';
case 'nef':
- return 'image/nef';
+ return 'image/x-nikon-nef';
+ case 'raf':
+ return 'image/x-fuji-raf';
+ case 'srw':
+ return 'image/x-samsung-srw';
default:
return '';
}
diff --git a/web/src/lib/utils/file-uploader.ts b/web/src/lib/utils/file-uploader.ts
index a96865b1df..8d7edc76d3 100644
--- a/web/src/lib/utils/file-uploader.ts
+++ b/web/src/lib/utils/file-uploader.ts
@@ -21,7 +21,7 @@ export const openFileUploadDialog = (
// When adding a content type that is unsupported by browsers, make sure
// to also add it to getFileMimeType() otherwise the upload will fail.
- fileSelector.accept = 'image/*,video/*,.heic,.heif,.dng,.3gp,.nef';
+ fileSelector.accept = 'image/*,video/*,.heic,.heif,.dng,.3gp,.nef,.srw,.raf';
fileSelector.onchange = async (e: Event) => {
const target = e.target as HTMLInputElement;
@@ -53,6 +53,7 @@ export const fileUploadHandler = async (
}, 2)
)
.subscribe();
+
const acceptedFile = files.filter((file) => {
const assetType = getFileMimeType(file).split('/')[0];
return assetType === 'video' || assetType === 'image';