mirror of
				https://github.com/KevinMidboe/immich.git
				synced 2025-10-29 17:40:28 +00:00 
			
		
		
		
	fix(server): handle missing reverse geocoding admin zones (#742)
This commit is contained in:
		@@ -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)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user