chore: scrobbling

This commit is contained in:
Cory Dransfeldt 2024-03-29 16:21:31 -07:00
parent 1f1f0e0c62
commit bb7fd5a6a6
No known key found for this signature in database

View file

@ -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)
}