Changeset e3a5aed in Klonkt for src/services/StatsService.js
- Timestamp:
- 06/30/2026 10:11:03 PM (2 months ago)
- Branches:
- main
- Children:
- d9c5eb8
- Parents:
- 65a0697
- File:
-
- 1 edited
-
src/services/StatsService.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/services/StatsService.js
r65a0697 re3a5aed 54 54 } 55 55 56 // The client IP (trust-proxy gives the real one), normalised: drop an IPv4-mapped-IPv6 prefix 57 // and a trailing :port so it matches what the admin sees + stores. 58 function clientIp(req) { 59 let ip = (req && (req.ip || (req.socket && req.socket.remoteAddress))) || ''; 60 if (ip.startsWith('::ffff:')) ip = ip.slice(7); 61 if (/^\d{1,3}(\.\d{1,3}){3}:\d+$/.test(ip)) ip = ip.split(':')[0]; 62 return ip; 63 } 64 export function currentIp(req) { return clientIp(req); } 65 66 // Admin-configured IPs to skip — so an owner browsing logged-OUT (incognito, another browser) 67 // doesn't inflate their own stats. Stored as a comma-separated app_setting. 68 export function getExcludedIps() { 69 return (getSetting('stats_exclude_ips', '') || '').split(',').map((s) => s.trim()).filter(Boolean); 70 } 71 export function setExcludedIps(list) { 72 const clean = [...new Set((list || []).map((s) => String(s).trim()).filter(Boolean))].slice(0, 20); 73 setSetting('stats_exclude_ips', clean.join(',')); 74 } 75 function isExcludedIp(req) { 76 try { const ip = clientIp(req); return !!ip && getExcludedIps().includes(ip); } catch { return false; } 77 } 78 56 79 // Lazy prepares — tables only exist after initializeDatabase(); this module is 57 80 // imported before that call. … … 90 113 91 114 export function recordPageview(siteId, req) { 92 if (!siteId || isOperator(req) || isBot(req) ) return;115 if (!siteId || isOperator(req) || isBot(req) || isExcludedIp(req)) return; 93 116 try { 94 117 const d = today(); … … 100 123 101 124 export function recordPostView(post, req) { 102 if (!post || !post.id || isOperator(req) || isBot(req) ) return;125 if (!post || !post.id || isOperator(req) || isBot(req) || isExcludedIp(req)) return; 103 126 try { 104 127 stmts().bumpPost.run(post.id);
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)