Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | 45x 4x | import { lastFmApiKey } from "./environment"; interface ITracksOfTheWeek { tracks: { track: { name: string; artist: { name: string; }; }[]; }; error?: number; message?: string; } export async function getTracksOfTheWeek(): Promise<ITracksOfTheWeek | null> { Iif (!lastFmApiKey) { console.error("No lastFmApiKey found"); return null; } const tracksOfTheWeekRes = await fetch( `https://ws.audioscrobbler.com/2.0/?method=chart.gettoptracks&api_key=${lastFmApiKey}&format=json` ); const tracksOfTheWeek = (await tracksOfTheWeekRes.json()) as ITracksOfTheWeek; Iif (tracksOfTheWeek.error) { console.error(`${tracksOfTheWeek.error}: ${tracksOfTheWeek.message}`); return null; } Iif (!tracksOfTheWeekRes.ok) { return null; } return tracksOfTheWeek; } |