chore: eventing + refactoring
This commit is contained in:
parent
13e7b489ef
commit
9a957159e9
3 changed files with 15 additions and 14 deletions
21
api/event.js
21
api/event.js
|
@ -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 })
|
||||
|
|
Reference in a new issue