]> git.example.dev Git - binbsis50-sm.git/commitdiff
added: lots of things, like gettign the status of the db now actually
author2weiEmu <saalbach.robert@outlook.de>
Thu, 12 Mar 2026 14:48:06 +0000 (15:48 +0100)
committer2weiEmu <saalbach.robert@outlook.de>
Thu, 12 Mar 2026 14:48:06 +0000 (15:48 +0100)
does things

pkg/dbhandling/dbhandling.go
public/css/index.css [new file with mode: 0644]
public/index.html
public/js/index.js
songmanager

index bc551c40df6b6145d58d28631f5682d2560c9690..a2b7c5f43b872be3bd7ea26edadd542b734356ef 100644 (file)
@@ -3,18 +3,32 @@ package dbhandling
 import (
        "context"
        "encoding/json"
-       "fmt"
        "net/http"
 
        "github.com/redis/go-redis/v9"
 )
 
 type DBSong struct {
+       Key string
+       ArtistName string
+       TrackName string
+       TrackViewURL string
+       PreviewURL string
+       ArtworkURL60 string
+       ArtworkURL100 string
+       DisplayArtistNames string
+       DisplayTrackName string
+}
 
+type DBRoom struct {
+       Name string
+       AssignedSongKeys []string
 }
 
 type DBStatusMessage struct {
        TotalSongCount int
+       AllSongs []DBSong
+       Rooms []DBRoom
 }
 
 type DBWrapper struct {
@@ -44,11 +58,64 @@ func (dbw *DBWrapper) GetDBStatus(w http.ResponseWriter, r *http.Request) {
        if err != nil {
                panic(err)
        }
-       fmt.Println(keys)
        key_count := len(keys)
 
+       // all zset type keys (because zsets are just keys)
+       // not the best way to scan this, and it's a weird
+       // way to get room information in the first place but it will have to do
+       allRooms := make([]DBRoom, 0)
+
+       all_keys, _, err := dbw.RedisDb.Scan(dbw.ctx, 0, "*", int64(key_count)).Result()
+       if err != nil {
+               panic(err)
+       }
+       for _, k := range all_keys {
+               t, err := dbw.RedisDb.Type(dbw.ctx, k).Result()
+               if err != nil {
+                       panic(err)
+               }
+               
+               if t == "zset" {
+                       assignedIds, err := dbw.RedisDb.ZRange(dbw.ctx, k, 0, -1).Result()
+                       if err != nil {
+                               panic(err)
+                       }
+
+                       allRooms = append(allRooms, DBRoom{
+                               Name: k,
+                               AssignedSongKeys: assignedIds,
+                       })
+               }
+       }
+
+
+       // honestly, the more i read the docs here maybe the guy used
+       // the hmset, hmget wrong or something, idk, i am not redoing the
+       // the database unless there ends up being significant performance implications
+       allSongs := make([]DBSong, key_count)
+       for i, k := range keys {
+               intf, err := dbw.RedisDb.HMGet(dbw.ctx, k, "artistName", "trackName", "trackViewUrl", "previewUrl", "artworkUrl60", "artworkUrl100", "displayArtistNames", "displayTrackName").Result()
+               if err != nil {
+                       panic(err)
+               }
+               song := DBSong{
+                       Key: k,
+                       ArtistName: intf[0].(string),
+                       TrackName: intf[1].(string),
+                       TrackViewURL: intf[2].(string),
+                       PreviewURL: intf[3].(string),
+                       ArtworkURL60: intf[4].(string),
+                       ArtworkURL100: intf[5].(string),
+                       DisplayArtistNames: intf[6].(string),
+                       DisplayTrackName: intf[7].(string),
+               }
+               allSongs[i] = song
+       }
+
        m := DBStatusMessage{
                TotalSongCount: key_count,
+               AllSongs: allSongs,
+               Rooms: allRooms,
        }
        b, err := json.Marshal(m)
        if err != nil {
diff --git a/public/css/index.css b/public/css/index.css
new file mode 100644 (file)
index 0000000..b9c15fc
--- /dev/null
@@ -0,0 +1,3 @@
+:root {
+       font-family: sans-serif;
+}
index f5f3550c6e377b7ca1250ece7d520f96d169f033..0472affad3dd0b64f4da7e5a02b24e88498745e2 100644 (file)
                        <h1>Current Status of db:</h1>
                        <button type="button" onclick="get_updated_status()">Get Status</button>
                        <h2>List of songs in the database:</h2>
-                       <ul id="db_status_song_list">
+                       <p>Filter songs here:</p>
+                       <input id="allSongFilterList" type="text"></input>
+                       <ul style="max-height: 200px; overflow-y: auto" id="db_status_song_list">
                        </ul>
 
                        <h2>Which rooms these songs are applied to</h2>
+                       <ul id="list_of_rooms">
+                               
+                       </ul>
                </div>
 
                <div>
index 641c95dc955ec491f3f7002c26fa0c870e908a32..de9d782786e68bd6d710731ccb4c0642aec22794 100644 (file)
@@ -1,8 +1,64 @@
-function get_updated_status() {
+let AllSongs = null
+let dbSongList = document.getElementById("db_status_song_list")
+
+
+let allSongFilterList = document.getElementById("allSongFilterList")
+allSongFilterList.oninput = (event) => {filterAllSongs(event)}
+
+function filterSongByAllAttrs(filter, song) {
+       return song.Key.includes(filter) || song.ArtistName.includes(filter) || 
+               song.TrackName.includes(filter)
+}
+
+function filterAllSongs(event) {
+       console.log("Firing input trigger")
+       let filterBy = allSongFilterList.value
+       console.log("Filtering by:" + filterBy)
+
+       if (AllSongs == null) { 
+               console.log("all songs was null")
+               return
+       }
+
+       dbSongList.innerHTML = ""
+
+       for (let song of AllSongs) {
+               if (filterSongByAllAttrs(filterBy, song)) {
+                       let li = document.createElement("li")
+                       li.innerText = song.Key
+                       dbSongList.appendChild(li)
+               }
+       }
+
+       console.log("function done")
+}
+
+
+async function get_updated_status() {
        console.log("updating database status...")
 
-       fetch("http://localhost:8000/api/db_status_update").then((response) => {
-               console.log(response)
+       fetch("http://localhost:8000/api/db_status_update", {'Accept': 'application/json', 'Content-type': 'application/json'}).then(async (response) => {
+               const body = await response.json()
+
+               // update total song list
+               AllSongs = body.AllSongs
+               for (let song of body.AllSongs) {
+                       let li = document.createElement("li")
+                       li.innerText = song.Key
+                       dbSongList.appendChild(li)
+               }
+
+               // update list of rooms
+               let room_list = document.getElementById("list_of_rooms")
+               for (let room of body.Rooms) {
+                       let header = document.createElement("h3")
+                       header.innerText = room.Name
+                       let new_list = document.createElement("ul")
+                       new_list.id = "room:" + room.Name
+
+                       room_list.appendChild(header)
+                       room_list.appendChild(new_list)
+               }
        })
 }
 
index 64fb0a77c1a6773fbb05f196d987a3f151381c46..bf81630300eaf6d101f71085540bec436a5e1db6 100755 (executable)
Binary files a/songmanager and b/songmanager differ