mirror of
https://github.com/umami-software/umami.git
synced 2026-02-19 03:55:37 +01:00
Use temporary fix
This commit is contained in:
parent
01da057b3e
commit
c6373adcb1
1 changed files with 14 additions and 9 deletions
|
|
@ -14,7 +14,17 @@ import {
|
||||||
} from './constants';
|
} from './constants';
|
||||||
import { NextApiRequestCollect } from 'pages/api/send';
|
import { NextApiRequestCollect } from 'pages/api/send';
|
||||||
|
|
||||||
let lookup;
|
let lookupPromise: any = null;
|
||||||
|
|
||||||
|
// This function returns the open DB. If it's already opening/open, just return the existing promise.
|
||||||
|
export function getLookup() {
|
||||||
|
if (!lookupPromise) {
|
||||||
|
console.log('debug: loading GeoLite2-City.mmdb');
|
||||||
|
const dir = path.join(process.cwd(), 'geo');
|
||||||
|
lookupPromise = maxmind.open(path.resolve(dir, 'GeoLite2-City.mmdb'));
|
||||||
|
}
|
||||||
|
return lookupPromise;
|
||||||
|
}
|
||||||
|
|
||||||
export function getIpAddress(req: NextApiRequestCollect) {
|
export function getIpAddress(req: NextApiRequestCollect) {
|
||||||
const customHeader = String(process.env.CLIENT_IP_HEADER).toLowerCase();
|
const customHeader = String(process.env.CLIENT_IP_HEADER).toLowerCase();
|
||||||
|
|
@ -108,16 +118,11 @@ export async function getLocation(ip: string, req: NextApiRequestCollect) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Database lookup
|
// Database lookup
|
||||||
if (!lookup) {
|
const lookup = await getLookup();
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log('debug: loading GeoLite2-City.mmdb');
|
|
||||||
const dir = path.join(process.cwd(), 'geo');
|
|
||||||
|
|
||||||
lookup = await maxmind.open(path.resolve(dir, 'GeoLite2-City.mmdb'));
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = lookup.get(ip);
|
const result = lookup.get(ip);
|
||||||
|
|
||||||
|
console.log('debug_result:', result);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
const country = result.country?.iso_code ?? result?.registered_country?.iso_code;
|
const country = result.country?.iso_code ?? result?.registered_country?.iso_code;
|
||||||
const subdivision1 = result.subdivisions?.[0]?.iso_code;
|
const subdivision1 = result.subdivisions?.[0]?.iso_code;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue