1
0
mirror of https://github.com/immich-app/immich.git synced 2025-01-12 15:32:36 +02:00

fix(server): handle missing reverse geocoding admin zones (#742)

This commit is contained in:
Zack Pollard 2022-09-23 16:14:42 +01:00 committed by GitHub
parent f377b64065
commit 040e02cfc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,7 +47,7 @@ function geocoderLookup(points: { latitude: number; longitude: number }[]) {
}); });
} }
const geocodingPrecisionLevels = [ "cities15000", "cities5000", "cities1000", "cities500" ] const geocodingPrecisionLevels = ['cities15000', 'cities5000', 'cities1000', 'cities500'];
export interface AdminCode { export interface AdminCode {
name: string; name: string;
@ -66,9 +66,9 @@ export interface GeoData {
featureCode: string; featureCode: string;
countryCode: string; countryCode: string;
cc2?: any; cc2?: any;
admin1Code: AdminCode; admin1Code?: AdminCode;
admin2Code: AdminCode; admin2Code?: AdminCode;
admin3Code: string; admin3Code?: any;
admin4Code?: any; admin4Code?: any;
population: string; population: string;
elevation: string; elevation: string;
@ -117,20 +117,23 @@ export class MetadataExtractionProcessor {
this.logLevel = this.configService.get('LOG_LEVEL') || ImmichLogLevel.SIMPLE; this.logLevel = this.configService.get('LOG_LEVEL') || ImmichLogLevel.SIMPLE;
} }
private async reverseGeocodeExif(latitude: number, longitude: number): Promise<{country: string, state: string, city: string}> { private async reverseGeocodeExif(
latitude: number,
longitude: number,
): Promise<{ country: string; state: string; city: string }> {
const geoCodeInfo = await geocoderLookup([{ latitude, longitude }]); const geoCodeInfo = await geocoderLookup([{ latitude, longitude }]);
const country = getName(geoCodeInfo.countryCode, 'en'); const country = getName(geoCodeInfo.countryCode, 'en');
const city = geoCodeInfo.name; const city = geoCodeInfo.name;
let state = ''; let state = '';
if (geoCodeInfo.admin2Code.name) state += geoCodeInfo.admin2Code.name; if (geoCodeInfo.admin2Code?.name) state += geoCodeInfo.admin2Code.name;
if (geoCodeInfo.admin1Code.name) { if (geoCodeInfo.admin1Code?.name) {
if (geoCodeInfo.admin2Code.name) state += ', '; if (geoCodeInfo.admin2Code?.name) state += ', ';
state += geoCodeInfo.admin1Code.name; state += geoCodeInfo.admin1Code.name;
} }
return { country, state, city } return { country, state, city };
} }
@Process(exifExtractionProcessorName) @Process(exifExtractionProcessorName)