chore: eventing + refactoring

This commit is contained in:
Cory Dransfeldt 2024-03-24 21:00:49 -07:00
parent 13e7b489ef
commit 9a957159e9
No known key found for this signature in database
3 changed files with 15 additions and 14 deletions

View file

@ -5,31 +5,34 @@ export default async (request, context) => {
const params = new URL(request['url']).searchParams
const ns = params.get('ns')
const page = params.get('page')
const num = params.get('num') || 'unknown'
const ig = params.get('ig')
const setUrl = (id, event) => `https://cdn.usefathom.com/?h=${encodeURIComponent(page)}&sid=CWSVCDJC&cid=${id}&name=${encodeURIComponent(event)}`
const lang = decodeURIComponent(params.get('lang'))
const nav = decodeURIComponent(params.get('nav'))
const notLang = !lang || lang === 'null' || lang === 'undefined'
const notNav = !nav || nav === 'null' || nav === 'undefined'
const ig = params.get('ig')
const setUrl = (id, event) => `https://cdn.usefathom.com/?h=${encodeURIComponent(page)}&sid=CWSVCDJC&cid=${id}&name=${encodeURIComponent(event)}`
const acceptLanguage = notLang ? request['headers'].get('accept-language') : lang
const userAgent = notNav ? request['headers'].get('user-agent') : nav
const headers = {
'Accept-Language': acceptLanguage,
'User-Agent': userAgent
}
let url
const id = crypto.createHash('md5').update(`${context['ip']}${context['geo']['city']}`).digest('hex')
const ids = getStore('ids')
const userId = await ids.get(id)
if (!userId) await ids.set(id, id)
const idVal = await ids.get(id)
if (ig) return
if (ns) {
const id = crypto.createHash('md5').update(`${context['ip']}${context['geo']['city']}`).digest('hex')
const ids = getStore('ids')
const userId = await ids.get(id)
if (!userId) await ids.set(id, id)
const idVal = await ids.get(id)
url = setUrl(idVal, 'noscript visit')
} else {
url = setUrl(num, 'Blocked visit')
url = setUrl(idVal, 'Blocked visit')
}
fetch(url, { headers })