From bb7fd5a6a6d69197a6b2065d933c09b5164d7391 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Fri, 29 Mar 2024 16:21:31 -0700 Subject: [PATCH] chore: scrobbling --- api/scrobble.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/api/scrobble.js b/api/scrobble.js index 6df9136f..e5212cca 100644 --- a/api/scrobble.js +++ b/api/scrobble.js @@ -13,11 +13,13 @@ const weekStop = () => { return nextSunday.toMillis() } -const twoWeeksAgo = DateTime.now().minus({ weeks: 2 }); -const filterOldScrobbles = (scrobbles) => scrobbles.filter(scrobble => { - let timestamp = DateTime.fromISO(scrobble.timestamp) - return timestamp.diff(twoWeeksAgo).as('weeks') <= -2 -}); +const filterOldScrobbles = (scrobbles) => { + const twoWeeksAgo = DateTime.now().minus({ weeks: 2 }); + return scrobbles.filter(obj => { + const timestamp = DateTime.fromISO(obj.timestamp); + return timestamp >= twoWeeksAgo; + }); +} export default async (request) => { const ACCOUNT_ID_PLEX = Netlify.env.get("ACCOUNT_ID_PLEX"); @@ -123,10 +125,6 @@ export default async (request) => { if (windowData?.['data']) windowUpdate['data'].push(trackScrobbleData) if (!windowData?.['data']) windowUpdate = { data: [trackScrobbleData] } windowUpdate = { data: filterOldScrobbles(windowUpdate.data) } - console.log('### SCROBBLE SET') - console.log(scrobbleUpdate); - console.log('### WINDOW SET') - console.log(windowUpdate); await scrobbles.setJSON(`${weekStop()}`, scrobbleUpdate) await scrobbles.setJSON('window', windowUpdate) }