fix: Oeffentliche Link-Besuche - gleiche IP innerhalb von 5 Minuten wird nicht erneut geloggt
This commit is contained in:
@@ -25,7 +25,24 @@ async function lookupLocation(ip) {
|
|||||||
// werden. linkType z.B. 'koepi_share'. Läuft bewusst asynchron/"fire and
|
// werden. linkType z.B. 'koepi_share'. Läuft bewusst asynchron/"fire and
|
||||||
// forget" im Hintergrund — ein Fehler hier darf niemals die eigentliche
|
// forget" im Hintergrund — ein Fehler hier darf niemals die eigentliche
|
||||||
// öffentliche Anfrage blockieren oder verlangsamen.
|
// öffentliche Anfrage blockieren oder verlangsamen.
|
||||||
|
//
|
||||||
|
// Dedup: dieselbe IP, die denselben Link innerhalb der letzten 5 Minuten schon
|
||||||
|
// besucht hat, wird nicht erneut geloggt (verhindert Log-Spam bei mehreren
|
||||||
|
// Klicks/Tab-Wechseln hintereinander, spart nebenbei auch unnötige
|
||||||
|
// Geolocation-Abfragen).
|
||||||
|
const DEDUP_WINDOW_MINUTES = 5;
|
||||||
function logPublicAccess({ linkType, path, ip }) {
|
function logPublicAccess({ linkType, path, ip }) {
|
||||||
|
try {
|
||||||
|
const recent = db.prepare(`
|
||||||
|
SELECT 1 FROM public_access_log
|
||||||
|
WHERE ip = ? AND path = ? AND created_at >= datetime('now','localtime',?)
|
||||||
|
LIMIT 1
|
||||||
|
`).get(ip || '', path || '', `-${DEDUP_WINDOW_MINUTES} minutes`);
|
||||||
|
if (recent) return; // kürzlich schon geloggt, nichts weiter tun
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Public-Access-Log Dedup-Fehler:', e.message);
|
||||||
|
}
|
||||||
|
|
||||||
lookupLocation(ip).then(location => {
|
lookupLocation(ip).then(location => {
|
||||||
try {
|
try {
|
||||||
db.prepare(`
|
db.prepare(`
|
||||||
|
|||||||
Reference in New Issue
Block a user