mux.HandleFunc("/api/db_status_update", DBwrapper.GetDBStatus)
mux.HandleFunc("/api/renameSong", DBwrapper.UpdateSongsFilename)
mux.HandleFunc("/api/updateSong", DBwrapper.UpdateSongStats)
+ mux.HandleFunc("/api/getSongFiles", DBwrapper.GetSongFiles)
mux.Handle("/", http.FileServer(http.Dir("./public/")))
listenPort := ":" + strconv.Itoa(*paramPort)
w.Write(b)
}
+
+type AllSongFiles struct {
+ SongFileList []string
+}
+
+/**
+ * Get a list of all song files
+ */
+func (dbw *DBWrapper) GetSongFiles(w http.ResponseWriter, r *http.Request) {
+ if r.Method != "GET" {
+ w.WriteHeader(http.StatusMethodNotAllowed)
+ return
+ }
+
+ songFiles, err := os.ReadDir(dbw.PathToSongs)
+ if err != nil {
+ panic(err)
+ }
+
+ fileNames := make([]string, 0)
+
+ for _, file := range songFiles {
+ fileNames = append(fileNames, file.Name())
+ }
+
+ allSongs := AllSongFiles{
+ SongFileList: fileNames,
+ }
+
+ b, err := json.Marshal(allSongs)
+ if err != nil {
+ panic(err)
+ }
+ w.Write(b)
+}
<p>Filter songs here:</p>
<input id="allSongFilterList" type="text"></input>
<ul style="max-height: 400px; overflow-y: auto" id="db_status_song_list">
+ </ul>
+ <h2>List of Song Files</h2>
+ <ul style="max-height: 400px; overflow-y: auto" id="song_file_list">
+
</ul>
<h2>Which rooms these songs are applied to</h2>
let AllSongs = null
+let AllFilenames = null
let currentEditSong = null
let dbSongList = document.getElementById("db_status_song_list")
let editElement = document.getElementById("editElement")
+let songFileList = document.getElementById("song_file_list")
+
let updateSongFile = document.getElementById("updateSongFile")
let editArtistName = document.getElementById("editArtistName")
return null
}
+function songHasValidFilename(song) {
+ return AllFilenames.includes(song.PreviewURL)
+}
function openEditElement(song) {
editElement.style.display = "block"
info.style.margin = "7px 5px 7px 5px"
info.style.padding = "2px 5px 2px 5px"
info.style.minWidth = "400px"
- info.innerText = "(" + song.Key + ") " + song.DisplayTrackName + " by " + song.DisplayArtistNames.replace("~", ", ")
+
+ let check = "❌"
+
+ if (songHasValidFilename(song)) {
+ check = "✅"
+ }
+
+ info.innerText = check + "(" + song.Key + ") " + song.DisplayTrackName + " by " + song.DisplayArtistNames.replace("~", ", ")
let but = document.createElement("button")
but.innerText = "Edit"
room_list.appendChild(new_list)
}
})
+
+ fetch("/api/getSongFiles",
+ {'Accept': 'application/json', 'Content-type': 'application/json'}
+ ).then(async (response) => {
+ const body = await response.json()
+ songFileList.innerHTML = ""
+ AllFilenames = body.SongFileList
+
+ for (let filename of body.SongFileList) {
+ let li = document.createElement("li")
+ li.innerText = filename
+ songFileList.appendChild(li)
+ }
+
+ })
}
window.onload = () => {