1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-01 08:31:59 +00:00

feat(server): enable exiftool largefilesupport (#9894)

This commit is contained in:
Floris Van den Abeele 2024-05-30 17:18:39 +02:00 committed by GitHub
parent 5ef2553bca
commit afa10ebcb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,6 @@
import { Inject, Injectable } from '@nestjs/common'; import { Inject, Injectable } from '@nestjs/common';
import { InjectDataSource, InjectRepository } from '@nestjs/typeorm'; import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
import { DefaultReadTaskOptions, Tags, exiftool } from 'exiftool-vendored'; import { DefaultExiftoolArgs, DefaultReadTaskOptions, ExifTool, Tags } from 'exiftool-vendored';
import geotz from 'geo-tz'; import geotz from 'geo-tz';
import { DummyValue, GenerateSql } from 'src/decorators'; import { DummyValue, GenerateSql } from 'src/decorators';
import { ExifEntity } from 'src/entities/exif.entity'; import { ExifEntity } from 'src/entities/exif.entity';
@ -21,13 +21,20 @@ export class MetadataRepository implements IMetadataRepository {
) { ) {
this.logger.setContext(MetadataRepository.name); this.logger.setContext(MetadataRepository.name);
} }
private exiftool: ExifTool = this.initExiftool();
async teardown() { async teardown() {
await exiftool.end(); await this.exiftool.end();
}
private initExiftool() {
// Enable exiftool LFS to parse metadata for files larger than 2GB.
const exiftoolArgs = ['-api', 'largefilesupport=1', ...DefaultExiftoolArgs];
return new ExifTool({ exiftoolArgs });
} }
readTags(path: string): Promise<ImmichTags | null> { readTags(path: string): Promise<ImmichTags | null> {
return exiftool return this.exiftool
.read(path, undefined, { .read(path, undefined, {
...DefaultReadTaskOptions, ...DefaultReadTaskOptions,
@ -46,12 +53,12 @@ export class MetadataRepository implements IMetadataRepository {
} }
extractBinaryTag(path: string, tagName: string): Promise<Buffer> { extractBinaryTag(path: string, tagName: string): Promise<Buffer> {
return exiftool.extractBinaryTagToBuffer(tagName, path); return this.exiftool.extractBinaryTagToBuffer(tagName, path);
} }
async writeTags(path: string, tags: Partial<Tags>): Promise<void> { async writeTags(path: string, tags: Partial<Tags>): Promise<void> {
try { try {
await exiftool.write(path, tags, ['-overwrite_original']); await this.exiftool.write(path, tags, ['-overwrite_original']);
} catch (error) { } catch (error) {
this.logger.warn(`Error writing exif data (${path}): ${error}`); this.logger.warn(`Error writing exif data (${path}): ${error}`);
} }