From 333ca8827e45a6f06e69d3d21309c6b4a9c01145 Mon Sep 17 00:00:00 2001 From: Pablo Molina Date: Wed, 13 Nov 2024 18:17:14 +0100 Subject: [PATCH] feat: use dateTimeOriginal to calculate album date (#14119) --- server/src/dtos/album.dto.ts | 5 +++-- server/src/utils/date-time.ts | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 server/src/utils/date-time.ts diff --git a/server/src/dtos/album.dto.ts b/server/src/dtos/album.dto.ts index b12847ee62537..76f4fdfc98f4a 100644 --- a/server/src/dtos/album.dto.ts +++ b/server/src/dtos/album.dto.ts @@ -7,6 +7,7 @@ import { AuthDto } from 'src/dtos/auth.dto'; import { UserResponseDto, mapUser } from 'src/dtos/user.dto'; import { AlbumEntity } from 'src/entities/album.entity'; import { AlbumUserRole, AssetOrder } from 'src/enum'; +import { getAssetDateTime } from 'src/utils/date-time'; import { Optional, ValidateBoolean, ValidateUUID } from 'src/validation'; export class AlbumInfoDto { @@ -164,8 +165,8 @@ export const mapAlbum = (entity: AlbumEntity, withAssets: boolean, auth?: AuthDt const hasSharedLink = entity.sharedLinks?.length > 0; const hasSharedUser = sharedUsers.length > 0; - let startDate = assets.at(0)?.fileCreatedAt || undefined; - let endDate = assets.at(-1)?.fileCreatedAt || undefined; + let startDate = getAssetDateTime(assets.at(0)); + let endDate = getAssetDateTime(assets.at(-1)); // Swap dates if start date is greater than end date. if (startDate && endDate && startDate > endDate) { [startDate, endDate] = [endDate, startDate]; diff --git a/server/src/utils/date-time.ts b/server/src/utils/date-time.ts new file mode 100644 index 0000000000000..e1578cbb19ad2 --- /dev/null +++ b/server/src/utils/date-time.ts @@ -0,0 +1,5 @@ +import { AssetEntity } from 'src/entities/asset.entity'; + +export const getAssetDateTime = (asset: AssetEntity | undefined) => { + return asset?.exifInfo?.dateTimeOriginal || asset?.fileCreatedAt; +};