chore(buffer): iron out the buffer issues
This commit is contained in:
@@ -39,17 +39,22 @@ export async function parseIp(ip?: string): Promise<GeoLocation> {
|
||||
}
|
||||
|
||||
try {
|
||||
const geo = await fetch(`${process.env.GEO_IP_HOST}/${ip}`, {
|
||||
const res = await fetch(`${process.env.GEO_IP_HOST}/${ip}`, {
|
||||
signal: AbortSignal.timeout(2000),
|
||||
});
|
||||
const res = (await geo.json()) as RemoteIpLookupResponse;
|
||||
|
||||
if (!res.ok) {
|
||||
return geo;
|
||||
}
|
||||
|
||||
const json = (await res.json()) as RemoteIpLookupResponse;
|
||||
|
||||
return {
|
||||
country: res.country,
|
||||
city: res.city,
|
||||
region: res.stateprov,
|
||||
longitude: res.longitude,
|
||||
latitude: res.latitude,
|
||||
country: json.country,
|
||||
city: json.city,
|
||||
region: json.stateprov,
|
||||
longitude: json.longitude,
|
||||
latitude: json.latitude,
|
||||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to fetch geo location for ip', { error });
|
||||
|
||||
@@ -9,7 +9,9 @@ export function parseUserAgent(ua?: string | null) {
|
||||
if (!ua) return parsedServerUa;
|
||||
const res = new UAParser(ua).getResult();
|
||||
|
||||
if (isServer(ua)) return parsedServerUa;
|
||||
if (isServer(ua)) {
|
||||
return parsedServerUa;
|
||||
}
|
||||
|
||||
return {
|
||||
os: res.os.name,
|
||||
@@ -77,7 +79,9 @@ function isServer(userAgent: string) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return !!userAgent.match(/^([^\s]+\/[\d.]+\s*)+$/);
|
||||
// Matches user agents like "Go-http-client/1.0" or "Go Http Client/1.0"
|
||||
// It should just match the first name (with optional spaces) and version
|
||||
return !!userAgent.match(/^[^\/]+\/[\d.]+$/);
|
||||
}
|
||||
|
||||
export function getDevice(ua: string) {
|
||||
|
||||
Reference in New Issue
Block a user