1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-01 08:31:59 +00: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 {
name: string;
@ -66,9 +66,9 @@ export interface GeoData {
featureCode: string;
countryCode: string;
cc2?: any;
admin1Code: AdminCode;
admin2Code: AdminCode;
admin3Code: string;
admin1Code?: AdminCode;
admin2Code?: AdminCode;
admin3Code?: any;
admin4Code?: any;
population: string;
elevation: string;
@ -117,20 +117,23 @@ export class MetadataExtractionProcessor {
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 country = getName(geoCodeInfo.countryCode, 'en');
const city = geoCodeInfo.name;
let state = '';
if (geoCodeInfo.admin2Code.name) state += geoCodeInfo.admin2Code.name;
if (geoCodeInfo.admin1Code.name) {
if (geoCodeInfo.admin2Code.name) state += ', ';
if (geoCodeInfo.admin2Code?.name) state += geoCodeInfo.admin2Code.name;
if (geoCodeInfo.admin1Code?.name) {
if (geoCodeInfo.admin2Code?.name) state += ', ';
state += geoCodeInfo.admin1Code.name;
}
return { country, state, city }
return { country, state, city };
}
@Process(exifExtractionProcessorName)