From: 2weiEmu Date: Mon, 16 Mar 2026 11:14:46 +0000 (+0100) Subject: updateds: X-Git-Url: https://git.saalbach.dev/?a=commitdiff_plain;h=189255d6f2f0bc8d614b0a51451a959b1c4009b6;p=binbsis50-sm.git updateds: --- diff --git a/main.go b/main.go index d256de5..8aca605 100644 --- a/main.go +++ b/main.go @@ -47,6 +47,7 @@ func main() { 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) diff --git a/pkg/dbhandling/dbhandling.go b/pkg/dbhandling/dbhandling.go index 6335981..ff63065 100644 --- a/pkg/dbhandling/dbhandling.go +++ b/pkg/dbhandling/dbhandling.go @@ -198,3 +198,38 @@ func (dbw *DBWrapper) GetDBStatus(w http.ResponseWriter, r *http.Request) { 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) +} diff --git a/public/index.html b/public/index.html index 48ef27f..96815a7 100644 --- a/public/index.html +++ b/public/index.html @@ -16,6 +16,10 @@

Filter songs here:

+

List of Song Files

+

Which rooms these songs are applied to

diff --git a/public/js/index.js b/public/js/index.js index 911dc32..6ff33b0 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1,8 +1,11 @@ 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") @@ -25,6 +28,9 @@ function getSongUsingKey(key) { return null } +function songHasValidFilename(song) { + return AllFilenames.includes(song.PreviewURL) +} function openEditElement(song) { editElement.style.display = "block" @@ -81,7 +87,14 @@ function newSongDisplayWithEdit(song) { 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" @@ -168,6 +181,21 @@ async function get_updated_status() { 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 = () => { diff --git a/songmanager b/songmanager index e691fdc..96de837 100755 Binary files a/songmanager and b/songmanager differ diff --git a/testing/songs/Soul Asylum_Runaway+Train.m4a b/testing/songs/Soul Asylum_Runaway+Train.m4a new file mode 100644 index 0000000..e69de29