Added schedule job to perform reverse geocoding if key is added after backing up assets (#305)

This commit is contained in:
Alex 2022-07-04 15:16:39 -05:00 committed by GitHub
parent e6d30d72fa
commit 357f7d1c31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 93 additions and 9 deletions

View file

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