Version
5.2.0
Question
I am trying to dynamically create a songs object for Amplituded.init()
. Basically I am creating a function getCoverArtURL and then passing it into a json object:
function getCoverArtURL(date) {
var basepath = "static/img/livephish_logos/"
var img_url = basepath + date + ".jpg"
return img_url
}
var songs = [
{
"name": "Shafty",
"artist": "Phish",
"url": "https://phish.in/audio/000/018/032/18032.mp3",
"cover_art_url": getCoverArtURL('1998-04-05')
},
{
"name": "Harry Hood",
"artist": "Phish",
"url": "https://phish.in/audio/000/020/602/20602.mp3",
"cover_art_url": getCoverArtURL('2000-06-6')
}
]
I essentially want the getCoverArtURL to default to specific image in my static/img/livephish_photos
. The options I have thought through are:
- Checking whether the source url is valid, though I haven’t found a function that does this
- Create a
fetch
function, but then I have to work with async/await or use a library that will check whether a source
I have added the default_album_art
to the Amplitude.init()
, but it seems this doesn’t handle server side 404s.
I’m very new to javascript but have worked quite a bit with other programming languages, so any help would be appreciated.