diff --git a/server/src/services/metadata.service.spec.ts b/server/src/services/metadata.service.spec.ts index 6e95430402..f275477d93 100644 --- a/server/src/services/metadata.service.spec.ts +++ b/server/src/services/metadata.service.spec.ts @@ -263,6 +263,35 @@ describe(MetadataService.name, () => { }); }); + it('should not delete latituide and longitude without reverse geocode', async () => { + // regression test for issue 17511 + mocks.asset.getByIds.mockResolvedValue([assetStub.withLocation]); + mocks.systemMetadata.get.mockResolvedValue({ reverseGeocoding: { enabled: false } }); + mocks.storage.stat.mockResolvedValue({ + size: 123_456, + mtime: assetStub.withLocation.fileModifiedAt, + mtimeMs: assetStub.withLocation.fileModifiedAt.valueOf(), + birthtimeMs: assetStub.withLocation.fileCreatedAt.valueOf(), + } as Stats); + mockReadTags({ + GPSLatitude: assetStub.withLocation.exifInfo!.latitude!, + GPSLongitude: assetStub.withLocation.exifInfo!.longitude!, + }); + + await sut.handleMetadataExtraction({ id: assetStub.image.id }); + expect(mocks.asset.getByIds).toHaveBeenCalledWith([assetStub.image.id], { faces: { person: false } }); + expect(mocks.asset.upsertExif).toHaveBeenCalledWith( + expect.objectContaining({ city: null, state: null, country: null }), + ); + expect(mocks.asset.update).toHaveBeenCalledWith({ + id: assetStub.withLocation.id, + duration: null, + fileCreatedAt: assetStub.withLocation.fileCreatedAt, + fileModifiedAt: assetStub.withLocation.fileModifiedAt, + localDateTime: new Date('2023-02-22T05:06:29.716Z'), + }); + }); + it('should apply reverse geocoding', async () => { mocks.asset.getByIds.mockResolvedValue([assetStub.withLocation]); mocks.systemMetadata.get.mockResolvedValue({ reverseGeocoding: { enabled: true } }); diff --git a/server/src/services/metadata.service.ts b/server/src/services/metadata.service.ts index a49bcac80e..5277ea2d68 100644 --- a/server/src/services/metadata.service.ts +++ b/server/src/services/metadata.service.ts @@ -200,15 +200,15 @@ export class MetadataService extends BaseService { const dates = this.getDates(asset, exifTags, stats); const { width, height } = this.getImageDimensions(exifTags); - let geo: ReverseGeocodeResult, latitude: number | null, longitude: number | null; - if (reverseGeocoding.enabled && this.hasGeo(exifTags)) { + let geo: ReverseGeocodeResult = { country: null, state: null, city: null }, + latitude: number | null = null, + longitude: number | null = null; + if (this.hasGeo(exifTags)) { latitude = exifTags.GPSLatitude; longitude = exifTags.GPSLongitude; - geo = await this.mapRepository.reverseGeocode({ latitude, longitude }); - } else { - latitude = null; - longitude = null; - geo = { country: null, state: null, city: null }; + if (reverseGeocoding.enabled) { + geo = await this.mapRepository.reverseGeocode({ latitude, longitude }); + } } const exifData: Insertable = {