+let songFileList = []
+/**
+ * Get the list of all named song files (raw filenames) using the API
+ * The API endpoint is /api/files/get
+ */
+async function getSongFileList() {
+ await fetch("/api/files/get", {'Accept': 'application/json', 'Content-type': 'application/json'}).then(async (response) => {
+ let body = await response.json()
+ songFileList = body
+ console.log(body)
+ })
+}
+
+getSongFileList()
+
let songList = []
let innerSongList = document.getElementById("innerSongList")
-
/**
* MAIN SONG ELEMENT
**/
</div>
*/
function NewSongElement(exists, songName, artistName, imageUrl, id) {
+ let wrapper = document.createElement("div")
+ wrapper.classList = "songElement"
+ wrapper.id = id
+ wrapper.songId = id.replace("song:", "")
+
+ let check = document.createElement("p")
+ check.innerText = "❌"
+ if (exists) {
+ check.innerText = "✅"
+ }
+
+ let songNameP = document.createElement("p")
+ songNameP.innerText = songName
+ let artistNameP = document.createElement("p")
+ artistNameP.innerText = artistName
+
+ let image = document.createElement("img")
+ image.src = imageUrl
+
+ let editButton = document.createElement("button")
+ editButton.innerText = "Edit"
+
+ let idP = document.createElement("p")
+ idP.innerText = id
+
+ wrapper.appendChild(check)
+ wrapper.appendChild(songNameP)
+ wrapper.appendChild(artistNameP)
+ wrapper.appendChild(image)
+ wrapper.appendChild(editButton)
+ wrapper.appendChild(idP)
+
+ return wrapper
}
+/**
+ * Check if the songs exists, withtout trying to download the full file
+ */
+function SongURLExists(url) {
+ console.log(url)
+ return songFileList.indexOf(url) != -1
+}
/**
* Get all the songs
**/
-async function getSongList() {
+function getSongList() {
// Empty the List
innerSongList.innerHTML = ""
fetch("/api/songs/get", {'Accept': 'application/json', 'Content-type': 'application/json'}).then(async (response) => {
- body = await response.json()
+ let body = await response.json()
console.log(body)
for (let i = 0; i < body.length; i++) {
+ let song = body[i]
+ let fileAvailable = SongURLExists(song.PreviewURL)
+
+ innerSongList.appendChild(NewSongElement(
+ fileAvailable, song.DisplayTrackName, song.DisplayArtistNames, song.ArtworkURL60, song.Key
+ ))
}
// using the elements in the body, create all the new songs in the list