diff --git a/server/apps/microservices/src/processors/metadata-extraction.processor.ts b/server/apps/microservices/src/processors/metadata-extraction.processor.ts index 1accb25bde..dc9e518396 100644 --- a/server/apps/microservices/src/processors/metadata-extraction.processor.ts +++ b/server/apps/microservices/src/processors/metadata-extraction.processor.ts @@ -23,6 +23,7 @@ import exifr from 'exifr'; import ffmpeg from 'fluent-ffmpeg'; import { readFile } from 'fs/promises'; import path from 'path'; +import sharp from 'sharp'; import { Repository } from 'typeorm/repository/Repository'; @Processor(metadataExtractionQueueName) @@ -50,10 +51,22 @@ export class MetadataExtractionProcessor { async extractExifInfo(job: Job) { try { const { asset, fileName, fileSize }: { asset: AssetEntity; fileName: string; fileSize: number } = job.data; - const exifData = await exifr.parse(asset.originalPath); + const exifData = await exifr.parse(asset.originalPath, { + tiff: true, + ifd0: true as any, + ifd1: true, + exif: true, + gps: true, + interop: true, + xmp: true, + icc: true, + iptc: true, + jfif: true, + ihdr: true, + }); if (!exifData) { - throw new Error(`can not fetch exif data from file ${asset.originalPath}`); + throw new Error(`can not parse exif data from file ${asset.originalPath}`); } const newExif = new ExifEntity(); @@ -107,6 +120,23 @@ export class MetadataExtractionProcessor { newExif.country = country || null; } + // Enrich metadata + if (!newExif.exifImageHeight || !newExif.exifImageWidth || !newExif.orientation) { + const metadata = await sharp(asset.originalPath).metadata(); + + if (newExif.exifImageHeight === null) { + newExif.exifImageHeight = metadata.height || null; + } + + if (newExif.exifImageWidth === null) { + newExif.exifImageWidth = metadata.width || null; + } + + if (newExif.orientation === null) { + newExif.orientation = metadata.orientation !== undefined ? `${metadata.orientation}` : null; + } + } + await this.exifRepository.save(newExif); } catch (e) { Logger.error(`Error extracting EXIF ${String(e)}`, 'extractExif');