Merge pull request #2388 from Maxime-J/subdivision1

Ensure country in region code
This commit is contained in:
Mike Cao 2023-11-30 14:48:01 -10:00 committed by GitHub
commit cde85d7db7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -107,11 +107,16 @@ export async function getLocation(ip, req) {
const result = lookup.get(ip); const result = lookup.get(ip);
if (result) { if (result) {
const country = result.country?.iso_code ?? result?.registered_country?.iso_code;
const subdivision1 = result.subdivisions?.[0]?.iso_code;
const subdivision2 = result.subdivisions?.[1]?.names?.en;
const city = result.city?.names?.en;
return { return {
country: result.country?.iso_code ?? result?.registered_country?.iso_code, country,
subdivision1: result.subdivisions?.[0]?.iso_code, subdivision1: getRegionCode(country, subdivision1),
subdivision2: result.subdivisions?.[1]?.names?.en, subdivision2,
city: result.city?.names?.en, city,
}; };
} }
} }