From 8f6a2554d0af83292af889f1e59c0fb1f372fb98 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Sat, 30 Mar 2024 15:43:43 -0700 Subject: [PATCH] chore: scrobbling --- api/music.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/api/music.js b/api/music.js index 8ef367cc..cc0f59c9 100644 --- a/api/music.js +++ b/api/music.js @@ -4,7 +4,15 @@ export default async (request) => { const API_KEY_MUSIC = Netlify.env.get('API_KEY_MUSIC'); const params = new URL(request['url']).searchParams const key = params.get('key') - const weeks = params.get('key')?.split(',') + const weeks = params.get('weeks') + let weeksArr = [] + let weeksString + + if (weeks.includes(',')) { + weeksArr = weeks.split(',') + } else { + weeksString = weeks + } if (!key) return new Response(JSON.stringify({ status: 'Bad request', @@ -20,15 +28,16 @@ export default async (request) => { const scrobbles = getStore('scrobbles') const scrobbleData = [] - if (weeks) { + if (weeksArr.length > 0) { weeks.forEach(async (week) => { const weekData = await scrobbles.get(week, { type: 'json'}) scrobbleData.push(weekData['data']) }) + } else if (weeksString) { + const weekData = await scrobbles.get(weeksString, { type: 'json'}) + scrobbleData.push(weekData['data']) } else { const windowData = await scrobbles.get('window', { type: 'json'}) - console.log(windowData) - console.log(scrobbleData) scrobbleData.push(windowData['data']) }