From 14172f9dd64ce91ba5cf51f82c53deb6a81d68a6 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Wed, 3 Jun 2026 17:22:48 -0700 Subject: create daily/unlimited mode, CDN audio file for daily mode --- src/helpers/fetchSolution.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/helpers/fetchSolution.ts') diff --git a/src/helpers/fetchSolution.ts b/src/helpers/fetchSolution.ts index 2ca2e68..10c4fa1 100644 --- a/src/helpers/fetchSolution.ts +++ b/src/helpers/fetchSolution.ts @@ -25,14 +25,27 @@ function getObfuscationKey(): Uint8Array { return new TextEncoder().encode(SALT + date); } +function decryptResponse(data: string): Song { + const obfuscationKey = getObfuscationKey(); + const obfuscatedBytes = hexToBytes(data); + const decrypted = xor(obfuscatedBytes, obfuscationKey); + return JSON.parse(new TextDecoder().decode(decrypted)) as Song; +} + export async function getDailySolution(): Promise { const solutionData = await fetch(`${API_URL}/today`); if (!solutionData.ok) { throw new Error(`Failed to fetch solution: ${solutionData.statusText}`); } const { data } = await solutionData.json(); - const obfuscationKey = getObfuscationKey(); - const obfuscatedBytes = hexToBytes(data); - const decrypted = xor(obfuscatedBytes, obfuscationKey); - return JSON.parse(new TextDecoder().decode(decrypted)) as Song; + return decryptResponse(data); +} + +export async function getSelectSolution(): Promise { + const solutionData = await fetch(`${API_URL}/select`); + if (!solutionData.ok) { + throw new Error(`Failed to fetch solution: ${solutionData.statusText}`); + } + const { data } = await solutionData.json(); + return decryptResponse(data); } -- cgit v1.2.3