mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
Added schedule job to perform reverse geocoding if key is added after backing up assets (#305)
This commit is contained in:
parent
e6d30d72fa
commit
357f7d1c31
5 changed files with 93 additions and 9 deletions
|
|
@ -21,6 +21,8 @@ import {
|
|||
objectDetectionProcessorName,
|
||||
videoMetadataExtractionProcessorName,
|
||||
metadataExtractionQueueName,
|
||||
reverseGeocodingProcessorName,
|
||||
IReverseGeocodingProcessor,
|
||||
} from '@app/job';
|
||||
|
||||
@Processor(metadataExtractionQueueName)
|
||||
|
|
@ -98,6 +100,28 @@ export class MetadataExtractionProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
@Process({ name: reverseGeocodingProcessorName })
|
||||
async reverseGeocoding(job: Job<IReverseGeocodingProcessor>) {
|
||||
const { exif } = job.data;
|
||||
|
||||
if (this.geocodingClient) {
|
||||
const geoCodeInfo: MapiResponse = await this.geocodingClient
|
||||
.reverseGeocode({
|
||||
query: [Number(exif.longitude), Number(exif.latitude)],
|
||||
types: ['country', 'region', 'place'],
|
||||
})
|
||||
.send();
|
||||
|
||||
const res: [] = geoCodeInfo.body['features'];
|
||||
|
||||
const city = res.filter((geoInfo) => geoInfo['place_type'][0] == 'place')[0]['text'];
|
||||
const state = res.filter((geoInfo) => geoInfo['place_type'][0] == 'region')[0]['text'];
|
||||
const country = res.filter((geoInfo) => geoInfo['place_type'][0] == 'country')[0]['text'];
|
||||
|
||||
await this.exifRepository.update({ id: exif.id }, { city, state, country });
|
||||
}
|
||||
}
|
||||
|
||||
@Process({ name: imageTaggingProcessorName, concurrency: 2 })
|
||||
async tagImage(job: Job) {
|
||||
const { asset }: { asset: AssetEntity } = job.data;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue