From 38767cad0f37dbb28d087a9cced3fe4e3d0b75ba Mon Sep 17 00:00:00 2001 From: bo0tzz Date: Fri, 7 Oct 2022 12:14:27 +0200 Subject: [PATCH 1/3] Update local-reverse-geocoder to 0.12.5 This version includes a fix to the error handling in that library, which was causing our code to silently fail and loop. See https://github.com/tomayac/local-reverse-geocoder/issues/58 for more detail. --- server/package-lock.json | 16 +++++++--------- server/package.json | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/server/package-lock.json b/server/package-lock.json index 62ebb7fd08..9cb57e7d52 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -36,7 +36,7 @@ "geo-tz": "^7.0.2", "i18n-iso-countries": "^7.5.0", "joi": "^17.5.0", - "local-reverse-geocoder": "^0.12.2", + "local-reverse-geocoder": "^0.12.5", "lodash": "^4.17.21", "luxon": "^3.0.3", "passport": "^0.6.0", @@ -7661,12 +7661,11 @@ } }, "node_modules/local-reverse-geocoder": { - "version": "0.12.2", - "resolved": "https://registry.npmjs.org/local-reverse-geocoder/-/local-reverse-geocoder-0.12.2.tgz", - "integrity": "sha512-kTSvDxGTuJoqx619jmHFoGCqFpBi0PPwyd7PDOLZCyo8mMEwJSMx713+ksOCihGpzUfO3hcclE7z/T43sY/IaA==", + "version": "0.12.5", + "resolved": "https://registry.npmjs.org/local-reverse-geocoder/-/local-reverse-geocoder-0.12.5.tgz", + "integrity": "sha512-FaH8+T29K9PQRiiqYlt+M9Qvq9GlSnWEnX0FTDXgPrNzQ9SWWYGEvO5uODwAD6sep9z19u/K/+Z3cw4AGVW97Q==", "dependencies": { "async": "^3.2.4", - "cors": "^2.8.5", "csv-parse": "^5.3.0", "debug": "^4.3.4", "kdt": "^0.1.0", @@ -17109,12 +17108,11 @@ "dev": true }, "local-reverse-geocoder": { - "version": "0.12.2", - "resolved": "https://registry.npmjs.org/local-reverse-geocoder/-/local-reverse-geocoder-0.12.2.tgz", - "integrity": "sha512-kTSvDxGTuJoqx619jmHFoGCqFpBi0PPwyd7PDOLZCyo8mMEwJSMx713+ksOCihGpzUfO3hcclE7z/T43sY/IaA==", + "version": "0.12.5", + "resolved": "https://registry.npmjs.org/local-reverse-geocoder/-/local-reverse-geocoder-0.12.5.tgz", + "integrity": "sha512-FaH8+T29K9PQRiiqYlt+M9Qvq9GlSnWEnX0FTDXgPrNzQ9SWWYGEvO5uODwAD6sep9z19u/K/+Z3cw4AGVW97Q==", "requires": { "async": "^3.2.4", - "cors": "^2.8.5", "csv-parse": "^5.3.0", "debug": "^4.3.4", "kdt": "^0.1.0", diff --git a/server/package.json b/server/package.json index 62c113b7db..7d7f5ea2b2 100644 --- a/server/package.json +++ b/server/package.json @@ -55,7 +55,7 @@ "geo-tz": "^7.0.2", "i18n-iso-countries": "^7.5.0", "joi": "^17.5.0", - "local-reverse-geocoder": "^0.12.2", + "local-reverse-geocoder": "^0.12.5", "lodash": "^4.17.21", "luxon": "^3.0.3", "passport": "^0.6.0", From 4f7e764fa0169a87a3ede75392ee6b3590397c56 Mon Sep 17 00:00:00 2001 From: Alex Tran Date: Fri, 7 Oct 2022 09:15:05 -0500 Subject: [PATCH 2/3] Fix typing --- .../metadata-extraction.processor.ts | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/server/apps/microservices/src/processors/metadata-extraction.processor.ts b/server/apps/microservices/src/processors/metadata-extraction.processor.ts index 27f2688d74..465b707304 100644 --- a/server/apps/microservices/src/processors/metadata-extraction.processor.ts +++ b/server/apps/microservices/src/processors/metadata-extraction.processor.ts @@ -20,7 +20,7 @@ import ffmpeg from 'fluent-ffmpeg'; import path from 'path'; import sharp from 'sharp'; import { Repository } from 'typeorm/repository/Repository'; -import geocoder, { InitOptions } from 'local-reverse-geocoder'; +import geocoder, { AddressObject, InitOptions } from 'local-reverse-geocoder'; import { getName } from 'i18n-iso-countries'; import { find } from 'geo-tz'; import * as luxon from 'luxon'; @@ -39,20 +39,20 @@ function geocoderLookup(points: { latitude: number; longitude: number }[]) { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore geocoder.lookUp(points, 1, (err, addresses) => { - resolve(addresses[0][0]); + resolve(addresses[0][0] as GeoData); }); }); } const geocodingPrecisionLevels = ['cities15000', 'cities5000', 'cities1000', 'cities500']; -export interface AdminCode { +export type AdminCode = { name: string; asciiName: string; geoNameId: string; -} +}; -export interface GeoData { +export type GeoData = { geoNameId: string; name: string; asciiName: string; @@ -63,8 +63,8 @@ export interface GeoData { featureCode: string; countryCode: string; cc2?: any; - admin1Code?: AdminCode; - admin2Code?: AdminCode; + admin1Code?: AdminCode | string; + admin2Code?: AdminCode | string; admin3Code?: any; admin4Code?: any; population: string; @@ -73,7 +73,7 @@ export interface GeoData { timezone: string; modificationDate: string; distance: number; -} +}; @Processor(QueueNameEnum.METADATA_EXTRACTION) export class MetadataExtractionProcessor { @@ -123,10 +123,22 @@ export class MetadataExtractionProcessor { const city = geoCodeInfo.name; let state = ''; - if (geoCodeInfo.admin2Code?.name) state += geoCodeInfo.admin2Code.name; - if (geoCodeInfo.admin1Code?.name) { - if (geoCodeInfo.admin2Code?.name) state += ', '; - state += geoCodeInfo.admin1Code.name; + + if (geoCodeInfo.admin2Code) { + const adminCode2 = geoCodeInfo.admin2Code as AdminCode; + state += adminCode2.name; + } + + if (geoCodeInfo.admin1Code) { + const adminCode1 = geoCodeInfo.admin1Code as AdminCode; + + if (geoCodeInfo.admin2Code) { + const adminCode2 = geoCodeInfo.admin2Code as AdminCode; + if (adminCode2.name) { + state += ', '; + } + } + state += adminCode1.name; } return { country, state, city }; From 82b8313da0b9d7a323e2cbedc0026d40e6f2c2c8 Mon Sep 17 00:00:00 2001 From: Alex Tran Date: Fri, 7 Oct 2022 09:16:45 -0500 Subject: [PATCH 3/3] Fix test --- .../src/processors/metadata-extraction.processor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/apps/microservices/src/processors/metadata-extraction.processor.ts b/server/apps/microservices/src/processors/metadata-extraction.processor.ts index 465b707304..b247215d43 100644 --- a/server/apps/microservices/src/processors/metadata-extraction.processor.ts +++ b/server/apps/microservices/src/processors/metadata-extraction.processor.ts @@ -20,7 +20,7 @@ import ffmpeg from 'fluent-ffmpeg'; import path from 'path'; import sharp from 'sharp'; import { Repository } from 'typeorm/repository/Repository'; -import geocoder, { AddressObject, InitOptions } from 'local-reverse-geocoder'; +import geocoder, { InitOptions } from 'local-reverse-geocoder'; import { getName } from 'i18n-iso-countries'; import { find } from 'geo-tz'; import * as luxon from 'luxon';