This repository has been archived on 2025-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
coryd.dev-eleventy/src/data/artists.js

47 lines
No EOL
1.1 KiB
JavaScript

import { createClient } from '@supabase/supabase-js'
import { parseCountryField } from '../../config/utilities/index.js'
const SUPABASE_URL = process.env.SUPABASE_URL
const SUPABASE_KEY = process.env.SUPABASE_KEY
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
const PAGE_SIZE = 1000
const fetchAllArtists = async () => {
let artists = []
let rangeStart = 0
while (true) {
const { data, error } = await supabase
.from('optimized_artists')
.select('*')
.range(rangeStart, rangeStart + PAGE_SIZE - 1)
if (error) {
console.error('Error fetching artists:', error)
break
}
artists = artists.concat(data)
if (data.length < PAGE_SIZE) break
rangeStart += PAGE_SIZE
}
return artists
}
const processArtists = (artists) => {
return artists.map(artist => ({
...artist,
country: parseCountryField(artist['country']),
}))
}
export default async function () {
try {
const artists = await fetchAllArtists()
return processArtists(artists)
} catch (error) {
console.error('Error fetching and processing artists data:', error)
return []
}
}