Analytics: Ereignisse annehmen
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cd9aebe4b1
commit
3a48e6e677
6 files changed
+472
-4
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import crypto from 'node:crypto';
|
||||
|
||||
const DAY = new Intl.DateTimeFormat('en-CA', { timeZone: 'Europe/Berlin', year: 'numeric', month: '2-digit', day: '2-digit' });
|
||||
|
||||
// Tagessalz nur im RAM; neu erzeugt, sobald sich der Kalendertag in Europe/Berlin ändert.
|
||||
export function createSalt({ now = Date.now, random = () => crypto.randomBytes(32) } = {}) {
|
||||
let day = null;
|
||||
let salt = null;
|
||||
const current = () => {
|
||||
const d = DAY.format(now());
|
||||
if (d !== day) { day = d; salt = random(); }
|
||||
return salt;
|
||||
};
|
||||
const hmac = (s) => crypto.createHmac('sha256', current()).update(s).digest('hex');
|
||||
return {
|
||||
visitorId: (site, ip, ua) => hmac(`${site}|${ip}|${ua}`).slice(0, 16),
|
||||
rateKey: (site, ip) => hmac(`${site}|${ip}`),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user