fix: read longitude and latitude when reverse geocoding is off (#17558)

This commit is contained in:
Andreas Tollkötter 2025-04-14 11:43:46 +02:00 committed by GitHub
parent 7562088fac
commit 8b00578c7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 7 deletions

View File

@ -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 } });

View File

@ -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;
if (reverseGeocoding.enabled) {
geo = await this.mapRepository.reverseGeocode({ latitude, longitude });
} else {
latitude = null;
longitude = null;
geo = { country: null, state: null, city: null };
}
}
const exifData: Insertable<Exif> = {