diff --git a/api/event.js b/api/event.js index 4ded8cb7..d770b6c2 100644 --- a/api/event.js +++ b/api/event.js @@ -1,40 +1,41 @@ import crypto from 'node:crypto' -import { getStore } from '@netlify/blobs'; +import { getStore } from '@netlify/blobs' export default async (request, context) => { - const ns = new URL(request['url']).searchParams.get('ns') - const page = new URL(request['url']).searchParams.get('page') - const num = new URL(request['url']).searchParams.get('num') - const lang = decodeURIComponent(new URL(request['url']).searchParams.get('lang')) - const nav = decodeURIComponent(new URL(request['url']).searchParams.get('nav')) - const ig = new URL(request['url']).searchParams.get('ig') + const params = new URL(request['url']).searchParams + const ns = params.get('ns') + const page = params.get('page') + const num = params.get('num') || 'unknown' + const lang = decodeURIComponent(params.get('lang')) + const nav = decodeURIComponent(params.get('nav')) + const ig = params.get('ig') const setUrl = (id, event) => `https://cdn.usefathom.com/?h=${encodeURIComponent(page)}&sid=CWSVCDJC&cid=${id}&name=${encodeURIComponent(event)}` const headers = {} - if (lang) headers['Accept-Language'] = lang; - if (nav) headers['User-Agent'] = nav; - let url; + if (lang) headers['Accept-Language'] = lang + if (nav) headers['User-Agent'] = nav + let url - if (ig) return; + if (ig) return if (ns) { - const id = crypto.createHash('md5').update(`${context['ip']}${context['geo']['city']}`).digest('hex'); + 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] ID: ${idVal}`) } else { - url = setUrl(num, `[Blocked visit] ID: ${num || 'unknown'}`) + url = setUrl(num, `[Blocked visit] ID: ${num}`) } fetch(url, { headers }) - .then((data) => { - console.log(data) - return {} - }) - .catch(err => { - console.log(err); - return {} - }); + .then((data) => { + console.log(data); + return {} + }) + .catch((err) => { + console.log(err) + return {} + }) return new Response(JSON.stringify({ status: 'success', @@ -45,4 +46,4 @@ export default async (request, context) => { export const config = { path: "/api/event", -}; \ No newline at end of file +} \ No newline at end of file diff --git a/package.json b/package.json index dcacf4a7..0d740dbe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "8.6.2", + "version": "8.7.1", "description": "The source for my personal site. Built using 11ty.", "type": "module", "scripts": {