Skip to content

Commit 9217757

Browse files
committed
Merge branch 'feat/nullable-dates' of https://github.com/immich-app/immich into feat/inline-offline-check
2 parents 77d3111 + c3c6ba6 commit 9217757

File tree

5 files changed

+21
-62
lines changed

5 files changed

+21
-62
lines changed

server/src/services/asset-media.service.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,6 @@ describe(AssetMediaService.name, () => {
542542

543543
it('should throw an error if the requested preview file does not exist', async () => {
544544
accessMock.asset.checkOwnerAccess.mockResolvedValue(new Set([assetStub.image.id]));
545-
546545
assetMock.getById.mockResolvedValue({
547546
...assetStub.image,
548547
files: [
@@ -563,7 +562,6 @@ describe(AssetMediaService.name, () => {
563562

564563
it('should fall back to preview if the requested thumbnail file does not exist', async () => {
565564
accessMock.asset.checkOwnerAccess.mockResolvedValue(new Set([assetStub.image.id]));
566-
567565
assetMock.getById.mockResolvedValue({
568566
...assetStub.image,
569567
files: [

server/src/services/library.service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,7 @@ export class LibraryService extends BaseService {
574574
}
575575

576576
const mtime = stat.mtime;
577-
578-
const isTimeUpdated = asset.fileModifiedAt === null || mtime.toISOString() !== asset.fileModifiedAt.toISOString();
577+
const isTimeUpdated = !asset.fileModifiedAt || mtime.toISOString() !== asset.fileModifiedAt.toISOString();
579578

580579
if (isTimeUpdated) {
581580
this.logger.verbose(

server/src/services/metadata.service.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BadRequestException, Injectable } from '@nestjs/common';
1+
import { Injectable } from '@nestjs/common';
22
import { ContainerDirectoryItem, ExifDateTime, Maybe, Tags } from 'exiftool-vendored';
33
import { firstDateTime } from 'exiftool-vendored/dist/FirstDateTime';
44
import { Insertable } from 'kysely';
@@ -588,17 +588,7 @@ export class MetadataService extends BaseService {
588588
}
589589
}
590590

591-
private getDates(asset: AssetEntity, exifTags: ImmichTags): AssetDatesDto {
592-
// We first assert that fileCreatedAt and fileModifiedAt are not null since that should be set to a non-null value before calling this function
593-
if (asset.fileCreatedAt === null) {
594-
this.logger.warn(`Asset ${asset.id} has no file creation date`);
595-
throw new BadRequestException(`Asset ${asset.id} has no file creation date`);
596-
}
597-
if (asset.fileModifiedAt === null) {
598-
this.logger.warn(`Asset ${asset.id} has no file modification date`);
599-
throw new BadRequestException(`Asset ${asset.id} has no file modification date`);
600-
}
601-
591+
private getDates(asset: AssetEntity, exifTags: ImmichTags) {
602592
const dateTime = firstDateTime(exifTags as Maybe<Tags>, EXIF_DATE_TAGS);
603593
this.logger.verbose(`Asset ${asset.id} date time is ${dateTime}`);
604594

@@ -630,11 +620,7 @@ export class MetadataService extends BaseService {
630620
localDateTime = earliestDate;
631621
}
632622

633-
if (localDateTime) {
634-
this.logger.verbose(`Asset ${asset.id} has a local time of ${localDateTime.toISOString()}`);
635-
} else {
636-
this.logger.verbose(`Asset ${asset.id} has no time set`);
637-
}
623+
this.logger.verbose(`Asset ${asset.id} has a local time of ${localDateTime.toISOString()}`);
638624

639625
let modifyDate = asset.fileModifiedAt;
640626
try {

server/src/services/storage-template.service.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,6 @@ export class StorageTemplateService extends BaseService {
310310

311311
const systemTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
312312
const zone = asset.exifInfo?.timeZone || systemTimeZone;
313-
314-
if (!asset.fileCreatedAt) {
315-
this.logger.log(`Asset ${asset.id} is missing fileCreatedAt, skipping storage template migration`);
316-
throw new Error(`Missing fileCreatedAt for asset ${asset.id}`);
317-
}
318-
319313
const dt = DateTime.fromJSDate(asset.fileCreatedAt, { zone });
320314

321315
for (const token of Object.values(storageTokens).flat()) {

server/test/medium/metadata.service.spec.ts

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ type TimeZoneTest = {
2929
description: string;
3030
serverTimeZone?: string;
3131
exifData: Record<string, any>;
32-
fileCreatedAt: Date;
33-
fileModifiedAt: Date;
3432
expected: {
3533
localDateTime: string;
3634
dateTimeOriginal: string;
@@ -60,8 +58,6 @@ describe(MetadataService.name, () => {
6058
const timeZoneTests: TimeZoneTest[] = [
6159
{
6260
description: 'should handle no time zone information',
63-
fileCreatedAt: new Date('2022-01-01T00:00:00.000Z'),
64-
fileModifiedAt: new Date('2022-01-01T00:00:00.000Z'),
6561
exifData: {
6662
DateTimeOriginal: '2022:01:01 00:00:00',
6763
},
@@ -73,8 +69,6 @@ describe(MetadataService.name, () => {
7369
},
7470
{
7571
description: 'should handle no time zone information and server behind UTC',
76-
fileCreatedAt: new Date('2022-01-01T00:00:00.000Z'),
77-
fileModifiedAt: new Date('2022-01-01T00:00:00.000Z'),
7872
serverTimeZone: 'America/Los_Angeles',
7973
exifData: {
8074
DateTimeOriginal: '2022:01:01 00:00:00',
@@ -87,8 +81,6 @@ describe(MetadataService.name, () => {
8781
},
8882
{
8983
description: 'should handle no time zone information and server ahead of UTC',
90-
fileCreatedAt: new Date('2022-01-01T00:00:00.000Z'),
91-
fileModifiedAt: new Date('2022-01-01T00:00:00.000Z'),
9284
serverTimeZone: 'Europe/Brussels',
9385
exifData: {
9486
DateTimeOriginal: '2022:01:01 00:00:00',
@@ -101,8 +93,6 @@ describe(MetadataService.name, () => {
10193
},
10294
{
10395
description: 'should handle no time zone information and server ahead of UTC in the summer',
104-
fileCreatedAt: new Date('2022-01-01T00:00:00.000Z'),
105-
fileModifiedAt: new Date('2022-01-01T00:00:00.000Z'),
10696
serverTimeZone: 'Europe/Brussels',
10797
exifData: {
10898
DateTimeOriginal: '2022:06:01 00:00:00',
@@ -115,8 +105,6 @@ describe(MetadataService.name, () => {
115105
},
116106
{
117107
description: 'should handle a +13:00 time zone',
118-
fileCreatedAt: new Date('2022-01-01T00:00:00.000Z'),
119-
fileModifiedAt: new Date('2022-01-01T00:00:00.000Z'),
120108
exifData: {
121109
DateTimeOriginal: '2022:01:01 00:00:00+13:00',
122110
},
@@ -128,32 +116,26 @@ describe(MetadataService.name, () => {
128116
},
129117
];
130118

131-
it.each(timeZoneTests)(
132-
'$description',
133-
async ({ exifData, serverTimeZone, expected, fileCreatedAt, fileModifiedAt }) => {
134-
// TODO: the TZ environment variable is no longer used, remove it
135-
process.env.TZ = serverTimeZone ?? undefined;
119+
it.each(timeZoneTests)('$description', async ({ exifData, serverTimeZone, expected }) => {
120+
process.env.TZ = serverTimeZone ?? undefined;
136121

137-
const { filePath } = await createTestFile(exifData);
138-
assetMock.getByIds.mockResolvedValue([
139-
{ id: 'asset-1', originalPath: filePath, fileCreatedAt, fileModifiedAt } as AssetEntity,
140-
]);
122+
const { filePath } = await createTestFile(exifData);
123+
assetMock.getByIds.mockResolvedValue([{ id: 'asset-1', originalPath: filePath } as AssetEntity]);
141124

142-
await sut.handleMetadataExtraction({ id: 'asset-1' });
125+
await sut.handleMetadataExtraction({ id: 'asset-1' });
143126

144-
expect(assetMock.upsertExif).toHaveBeenCalledWith(
145-
expect.objectContaining({
146-
dateTimeOriginal: new Date(expected.dateTimeOriginal),
147-
timeZone: expected.timeZone,
148-
}),
149-
);
127+
expect(assetMock.upsertExif).toHaveBeenCalledWith(
128+
expect.objectContaining({
129+
dateTimeOriginal: new Date(expected.dateTimeOriginal),
130+
timeZone: expected.timeZone,
131+
}),
132+
);
150133

151-
expect(assetMock.update).toHaveBeenCalledWith(
152-
expect.objectContaining({
153-
localDateTime: new Date(expected.localDateTime),
154-
}),
155-
);
156-
},
157-
);
134+
expect(assetMock.update).toHaveBeenCalledWith(
135+
expect.objectContaining({
136+
localDateTime: new Date(expected.localDateTime),
137+
}),
138+
);
139+
});
158140
});
159141
});

0 commit comments

Comments
 (0)