Mark obvious bot sessions with robot avatars

Detect automated sessions from known data center cities (Council Bluffs, Santa Clara, Ashburn, etc.) with zero session duration, and display them with robot avatars instead of human faces. This provides an instant visual indicator in the Sessions UI without needing to inspect city/duration for each session.

Uses both conditions (city match AND zero duration) to minimize false positives while reliably catching obvious bots.
This commit is contained in:
Arthur Sepiol 2025-12-07 20:35:38 +03:00
parent 81e27fc18c
commit 5413ce5d61
4 changed files with 43 additions and 10 deletions

25
src/lib/botDetection.ts Normal file
View file

@ -0,0 +1,25 @@
const BOT_CITIES = [
'Council Bluffs',
'North Richland Hills',
'Santa Clara',
'Ashburn',
'The Dalles',
'Boardman',
'Quincy',
];
export function isLikelyBot(session: {
city?: string;
firstAt?: string | Date;
lastAt?: string | Date;
}): boolean {
const cityMatch =
session.city && BOT_CITIES.some(botCity => session.city?.toLowerCase() === botCity.toLowerCase());
const zeroDuration =
session.firstAt &&
session.lastAt &&
new Date(session.firstAt).getTime() === new Date(session.lastAt).getTime();
return !!(cityMatch && zeroDuration);
}