chore: update music api

This commit is contained in:
Cory Dransfeldt 2024-03-30 20:30:44 -07:00
parent 75d2b7f693
commit 178546935c
No known key found for this signature in database

View file

@ -4,15 +4,7 @@ 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('weeks')
let weeksArr = []
let weeksString
if (weeks?.includes(',')) {
weeksArr = weeks.split(',')
} else {
weeksString = weeks
}
const week = params.get('week')
if (!key) return new Response(JSON.stringify({
status: 'Bad request',
@ -33,13 +25,8 @@ export default async (request) => {
const artistsMap = await artists.get('artists-map', { type: 'json' })
const albumsMap = await albums.get('albums-map', { type: 'json' })
if (weeksArr.length > 0) {
weeksArr.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'})
if (week) {
const weekData = await scrobbles.get(week, { type: 'json'})
scrobbleData.push(...weekData['data'])
} else {
const windowData = await scrobbles.get('window', { type: 'json'})