aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers/fetchSolution.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/helpers/fetchSolution.ts')
-rw-r--r--src/helpers/fetchSolution.ts21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/helpers/fetchSolution.ts b/src/helpers/fetchSolution.ts
index 10c4fa1..e3010fe 100644
--- a/src/helpers/fetchSolution.ts
+++ b/src/helpers/fetchSolution.ts
@@ -20,25 +20,32 @@ function xor(data: Uint8Array, key: Uint8Array): Uint8Array {
return output;
}
-function getObfuscationKey(): Uint8Array {
- const date = new Date().toISOString().split('T')[0];
+function getObfuscationKey(date = new Date().toISOString().split('T')[0]): Uint8Array {
return new TextEncoder().encode(SALT + date);
}
-function decryptResponse(data: string): Song {
- const obfuscationKey = getObfuscationKey();
+function decryptResponse(data: string, date?: string): Song {
+ const obfuscationKey = getObfuscationKey(date);
const obfuscatedBytes = hexToBytes(data);
const decrypted = xor(obfuscatedBytes, obfuscationKey);
return JSON.parse(new TextDecoder().decode(decrypted)) as Song;
}
-export async function getDailySolution(): Promise<Song> {
+export interface DailySolution {
+ date: string;
+ song: Song;
+}
+
+export async function getDailySolution(): Promise<DailySolution> {
const solutionData = await fetch(`${API_URL}/today`);
if (!solutionData.ok) {
throw new Error(`Failed to fetch solution: ${solutionData.statusText}`);
}
- const { data } = await solutionData.json();
- return decryptResponse(data);
+ const { data, date } = await solutionData.json();
+ return {
+ date,
+ song: decryptResponse(data, date),
+ };
}
export async function getSelectSolution(): Promise<Song> {
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage