Skip to content

High performance self-hosted photo and video management solution.

fix(server): consider asset creation date when EXIF is missing (#21586)

Riccardo Ruspoli8747fc4935b2
diff --git a/server/src/services/metadata.service.ts b/server/src/services/metadata.service.ts
index de54fca904..94ccd41ff5 100644
--- a/server/src/services/metadata.service.ts
+++ b/server/src/services/metadata.service.ts
@@ -835,7 +835,11 @@ export class MetadataService extends BaseService {
}
}
- private getDates(asset: { id: string; originalPath: string }, exifTags: ImmichTags, stats: Stats) {
+ private getDates(
+ asset: { id: string; originalPath: string; fileCreatedAt: Date },
+ exifTags: ImmichTags,
+ stats: Stats,
+ ) {
const result = firstDateTime(exifTags);
const tag = result?.tag;
const dateTime = result?.dateTime;
@@ -864,7 +868,12 @@ export class MetadataService extends BaseService {
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 = stats.birthtimeMs ? new Date(Math.min(stats.mtimeMs, stats.birthtimeMs)) : stats.mtime;
+ const earliestDate = new Date(
+ 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}`,
);