feat: additional album release details
This commit is contained in:
parent
eb6b227006
commit
6e5bada890
5 changed files with 49 additions and 55 deletions
|
@ -26,32 +26,6 @@ export default async (request) => {
|
|||
const artistKey = sanitizeMediaString(artist).replace(/\s+/g, '-').toLowerCase()
|
||||
const albumKey = `${artistKey}-${sanitizeMediaString(album).replace(/\s+/g, '-').toLowerCase()}`
|
||||
|
||||
const { data: albumData, error: albumError } = await supabase
|
||||
.from('albums')
|
||||
.select('*')
|
||||
.eq('key', albumKey)
|
||||
.single()
|
||||
|
||||
if (albumError && albumError.code === 'PGRST116') {
|
||||
const { error: insertAlbumError } = await supabase.from('albums').insert([
|
||||
{
|
||||
mbid: null,
|
||||
image: `https://coryd.dev/media/albums/${albumKey}.jpg`,
|
||||
key: albumKey,
|
||||
name: album,
|
||||
tentative: true
|
||||
}
|
||||
])
|
||||
|
||||
if (insertAlbumError) {
|
||||
console.error('Error inserting album into Supabase:', insertAlbumError.message)
|
||||
return new Response(JSON.stringify({ status: 'error', message: insertAlbumError.message }), { headers: { "Content-Type": "application/json" } })
|
||||
}
|
||||
} else if (albumError) {
|
||||
console.error('Error querying album from Supabase:', albumError.message)
|
||||
return new Response(JSON.stringify({ status: 'error', message: albumError.message }), { headers: { "Content-Type": "application/json" } })
|
||||
}
|
||||
|
||||
const { data: artistData, error: artistError } = await supabase
|
||||
.from('artists')
|
||||
.select('*')
|
||||
|
@ -78,6 +52,32 @@ export default async (request) => {
|
|||
return new Response(JSON.stringify({ status: 'error', message: artistError.message }), { headers: { "Content-Type": "application/json" } })
|
||||
}
|
||||
|
||||
const { data: albumData, error: albumError } = await supabase
|
||||
.from('albums')
|
||||
.select('*')
|
||||
.eq('key', albumKey)
|
||||
.single()
|
||||
|
||||
if (albumError && albumError.code === 'PGRST116') {
|
||||
const { error: insertAlbumError } = await supabase.from('albums').insert([
|
||||
{
|
||||
mbid: null,
|
||||
image: `https://coryd.dev/media/albums/${albumKey}.jpg`,
|
||||
key: albumKey,
|
||||
name: album,
|
||||
tentative: true
|
||||
}
|
||||
])
|
||||
|
||||
if (insertAlbumError) {
|
||||
console.error('Error inserting album into Supabase:', insertAlbumError.message)
|
||||
return new Response(JSON.stringify({ status: 'error', message: insertAlbumError.message }), { headers: { "Content-Type": "application/json" } })
|
||||
}
|
||||
} else if (albumError) {
|
||||
console.error('Error querying album from Supabase:', albumError.message)
|
||||
return new Response(JSON.stringify({ status: 'error', message: albumError.message }), { headers: { "Content-Type": "application/json" } })
|
||||
}
|
||||
|
||||
const { error: listenError } = await supabase.from('listens').insert([
|
||||
{
|
||||
artist_name: artist,
|
||||
|
|
Reference in a new issue