From 20a4f11818475214c108ef84c09ce58be007534d Mon Sep 17 00:00:00 2001 From: meowarex Date: Fri, 3 Apr 2026 01:26:44 +1100 Subject: [PATCH] Add Ratelimiting <3 --- plugins/radiant-lyrics-luna/src/index.ts | 27 ++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/plugins/radiant-lyrics-luna/src/index.ts b/plugins/radiant-lyrics-luna/src/index.ts index e00a287..0fed92c 100644 --- a/plugins/radiant-lyrics-luna/src/index.ts +++ b/plugins/radiant-lyrics-luna/src/index.ts @@ -40,6 +40,16 @@ const toastErr = (msg: string) => // clean up resources export const unloads = new Set(); +let cachedPublicIP: string | undefined; +async function getPublicIPv4(): Promise { + if (cachedPublicIP) return cachedPublicIP; + try { + const res = await fetch("https://api.ipify.org?format=text"); + if (res.ok) cachedPublicIP = (await res.text()).trim(); + } catch {} + return cachedPublicIP; +} + // MARKER: Player Market UI (Ensure new UI is enabled) function enablePlayerMarketUI() { @@ -359,12 +369,13 @@ const resyncLyrics = async (): Promise => { const url = `https://api.atomix.one/rl-api${params}`; try { - const res = await fetch(url, { - headers: { - "P-Access-Token-Id": "58hy4s86", - "P-Access-Token": "xjehy2lfg5h5mjwotoxrcqugam", - }, - }); + const clientIP = await getPublicIPv4(); + const resyncHeaders: Record = { + "P-Access-Token-Id": "58hy4s86", + "P-Access-Token": "xjehy2lfg5h5mjwotoxrcqugam", + }; + resyncHeaders["x-client-ip"] = clientIP ?? "null"; + const res = await fetch(url, { headers: resyncHeaders }); if (res.status === 404) { toast("No lyrics found for this track"); return; @@ -2178,6 +2189,8 @@ const fetchLyrics = async ( "P-Access-Token-Id": "58hy4s86", "P-Access-Token": "xjehy2lfg5h5mjwotoxrcqugam", }; + const clientIP = await getPublicIPv4(); + rlApiHeaders["x-client-ip"] = clientIP ?? "null"; const tryFetch = async (url: string): Promise => { try { @@ -2335,6 +2348,8 @@ const romanizeLines = async (lineTexts: string[]): Promise => { if (url.includes("api.atomix.one")) { romanizeHeaders["P-Access-Token-Id"] = "58hy4s86"; romanizeHeaders["P-Access-Token"] = "xjehy2lfg5h5mjwotoxrcqugam"; + const ip = await getPublicIPv4(); + romanizeHeaders["x-client-ip"] = ip ?? "null"; } const res = await fetch(url, { method: "POST",