diff options
Diffstat (limited to 'src/helpers')
| -rw-r--r-- | src/helpers/fetchSolution.ts | 32 | ||||
| -rw-r--r-- | src/helpers/searchSong.ts | 5 |
2 files changed, 35 insertions, 2 deletions
diff --git a/src/helpers/fetchSolution.ts b/src/helpers/fetchSolution.ts index d877d8f..b7895bb 100644 --- a/src/helpers/fetchSolution.ts +++ b/src/helpers/fetchSolution.ts @@ -77,6 +77,20 @@ export async function getDailySolution(): Promise<DailySolution> { }; } +export async function getDailyMVSolution(): Promise<DailySolution> { + const solutionData = await fetch(`${API_URL}/todayMV`); + if (!solutionData.ok) { + throw new Error(`Failed to fetch MV solution: ${solutionData.statusText}`); + } + const { data, date, sessionToken, initialSig } = await solutionData.json(); + return { + date, + sessionToken, + initialSig, + song: decryptResponse(data, date), + }; +} + export async function submitDailyGuess( payload: SubmitDailyGuessRequest ): Promise<SubmitDailyGuessResponse> { @@ -95,6 +109,24 @@ export async function submitDailyGuess( return (await response.json()) as SubmitDailyGuessResponse; } +export async function submitDailyMVGuess( + payload: SubmitDailyGuessRequest +): Promise<SubmitDailyGuessResponse> { + const response = await fetch(`${API_URL}/guessMV`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(payload), + }); + + if (!response.ok) { + throw new Error(`Failed to submit MV guess: ${response.statusText}`); + } + + return (await response.json()) as SubmitDailyGuessResponse; +} + export async function getSelectSolution(): Promise<Song> { const solutionData = await fetch(`${API_URL}/select`); if (!solutionData.ok) { diff --git a/src/helpers/searchSong.ts b/src/helpers/searchSong.ts index 62091b6..3bbecad 100644 --- a/src/helpers/searchSong.ts +++ b/src/helpers/searchSong.ts @@ -5,10 +5,11 @@ function fuzzyMatch(input: string): string { return input.toLowerCase().replace(/[^0-9a-z ]/gi, ""); } -export function searchSong(searchTerm: string): Song[] { +export function searchSong(searchTerm: string, pool?: Song[]): Song[] { const normalizedSearch = fuzzyMatch(searchTerm); + const source = pool ?? songs; //if no pool is provided, use the default k-heardle songs list - return songs + return source .filter((song: Song) => { const songName = fuzzyMatch(song.name); const songArtist = fuzzyMatch(song.artist); |
