Something went wrong. Try again.
data endpoint for entity 90008 (aka. a website)
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263import { env } from '$env/dynamic/private';
let pushTimestamps: number[] = [];const HARD_WINDOW_MS = 20_000; // 20 secondsconst HARD_MAX_PUSHES = 2; // max 2 notifs per 20 seconds
let lastPushedContent = '';let lastPushedContentTime = 0;const DEDUPE_WINDOW_MS = 60_000; // 1 minute deduplication
export const pushNotification = (_content: string) => { const now = Date.now(); pushTimestamps = pushTimestamps.filter((t) => now - t < HARD_WINDOW_MS); if (pushTimestamps.length >= HARD_MAX_PUSHES) { console.log('pushNotification dropped by hard internal rate limit floor'); return; }
// Drop exact duplicate messages repeated within 60 seconds const normalized = _content.trim().toLowerCase(); if (normalized === lastPushedContent && now - lastPushedContentTime < DEDUPE_WINDOW_MS) { console.log('pushNotification dropped as duplicate content'); return; } lastPushedContent = normalized; lastPushedContentTime = now; pushTimestamps.push(now);
const content = encodeURIComponent(_content); try { if (env.BARK_DEVICE_ID) { fetch( `https://api.day.app/${env.BARK_DEVICE_ID}/gaze.systems/${content}?icon=https://gaze.systems/icons/gaze_site.webp` ); } if (env.DISCORD_NOTIF_WEBHOOK) { fetch(env.DISCORD_NOTIF_WEBHOOK, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ content: '<@853064602904166430>', allowed_mentions: { users: ['853064602904166430'] }, embeds: [ { id: 677465216, title: _content, footer: { text: 'notif from gaze.systems' } } ] }) }); } } catch (err) { console.log(`failed to push notification: ${err}`); }};