mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
feat: exif medium tests (#23561)
This commit is contained in:
@@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
|
||||
import { ContainerDirectoryItem, ExifDateTime, Tags } from 'exiftool-vendored';
|
||||
import { Insertable } from 'kysely';
|
||||
import _ from 'lodash';
|
||||
import { Duration } from 'luxon';
|
||||
import { DateTime, Duration } from 'luxon';
|
||||
import { Stats } from 'node:fs';
|
||||
import { constants } from 'node:fs/promises';
|
||||
import { join, parse } from 'node:path';
|
||||
@@ -866,31 +866,40 @@ export class MetadataService extends BaseService {
|
||||
this.logger.debug(`No timezone information found for asset ${asset.id}: ${asset.originalPath}`);
|
||||
}
|
||||
|
||||
let dateTimeOriginal = dateTime?.toDate();
|
||||
let localDateTime = dateTime?.toDateTime().setZone('UTC', { keepLocalTime: true }).toJSDate();
|
||||
let dateTimeOriginal = dateTime?.toDateTime();
|
||||
|
||||
// do not let JavaScript use local timezone
|
||||
if (dateTimeOriginal && !dateTime?.hasZone) {
|
||||
dateTimeOriginal = dateTimeOriginal.setZone('UTC', { keepLocalTime: true });
|
||||
}
|
||||
|
||||
// align with whatever timeZone we chose
|
||||
dateTimeOriginal = dateTimeOriginal?.setZone(timeZone ?? 'UTC');
|
||||
|
||||
// store as "local time"
|
||||
let localDateTime = dateTimeOriginal?.setZone('UTC', { keepLocalTime: true });
|
||||
|
||||
if (!localDateTime || !dateTimeOriginal) {
|
||||
// FileCreateDate is not available on linux, likely because exiftool hasn't integrated the statx syscall yet
|
||||
// birthtime is not available in Docker on macOS, so it appears as 0
|
||||
const earliestDate = new Date(
|
||||
const earliestDate = DateTime.fromMillis(
|
||||
Math.min(
|
||||
asset.fileCreatedAt.getTime(),
|
||||
stats.birthtimeMs ? Math.min(stats.mtimeMs, stats.birthtimeMs) : stats.mtime.getTime(),
|
||||
),
|
||||
);
|
||||
this.logger.debug(
|
||||
`No exif date time found, falling back on ${earliestDate.toISOString()}, earliest of file creation and modification for asset ${asset.id}: ${asset.originalPath}`,
|
||||
`No exif date time found, falling back on ${earliestDate.toISO()}, earliest of file creation and modification for asset ${asset.id}: ${asset.originalPath}`,
|
||||
);
|
||||
dateTimeOriginal = localDateTime = earliestDate;
|
||||
}
|
||||
|
||||
this.logger.verbose(
|
||||
`Found local date time ${localDateTime.toISOString()} for asset ${asset.id}: ${asset.originalPath}`,
|
||||
);
|
||||
this.logger.verbose(`Found local date time ${localDateTime.toISO()} for asset ${asset.id}: ${asset.originalPath}`);
|
||||
|
||||
return {
|
||||
dateTimeOriginal,
|
||||
timeZone,
|
||||
localDateTime,
|
||||
localDateTime: localDateTime.toJSDate(),
|
||||
dateTimeOriginal: dateTimeOriginal.toJSDate(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user