mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-07 03:06:40 +00:00
Chungus
This commit is contained in:
@@ -1,10 +1,42 @@
|
||||
import logger from "@server/logger";
|
||||
import { maxmindLookup } from "@server/db/maxmind";
|
||||
import axios from "axios";
|
||||
import config from "./config";
|
||||
import { tokenManager } from "./tokenManager";
|
||||
import logger from "@server/logger";
|
||||
|
||||
export async function getCountryCodeForIp(
|
||||
ip: string
|
||||
): Promise<string | undefined> {
|
||||
try {
|
||||
if (!maxmindLookup) {
|
||||
logger.warn(
|
||||
"MaxMind DB path not configured, cannot perform GeoIP lookup"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const result = maxmindLookup.get(ip);
|
||||
|
||||
if (!result || !result.country) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { country } = result;
|
||||
|
||||
logger.debug(
|
||||
`GeoIP lookup successful for IP ${ip}: ${country.iso_code}`
|
||||
);
|
||||
|
||||
return country.iso_code;
|
||||
} catch (error) {
|
||||
logger.error("Error fetching config in verify session:", error);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
export async function remoteGetCountryCodeForIp(
|
||||
ip: string
|
||||
): Promise<string | undefined> {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
|
||||
Reference in New Issue
Block a user