From 3ab33f63d42801d9b4480ef427e76c93d7ff942e Mon Sep 17 00:00:00 2001 From: 2weiEmu Date: Thu, 12 Mar 2026 15:48:06 +0100 Subject: [PATCH] added: lots of things, like gettign the status of the db now actually does things --- pkg/dbhandling/dbhandling.go | 71 ++++++++++++++++++++++++++++++++++- public/css/index.css | 3 ++ public/index.html | 7 +++- public/js/index.js | 62 ++++++++++++++++++++++++++++-- songmanager | Bin 10580925 -> 10598086 bytes 5 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 public/css/index.css diff --git a/pkg/dbhandling/dbhandling.go b/pkg/dbhandling/dbhandling.go index bc551c4..a2b7c5f 100644 --- a/pkg/dbhandling/dbhandling.go +++ b/pkg/dbhandling/dbhandling.go @@ -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 index 0000000..b9c15fc --- /dev/null +++ b/public/css/index.css @@ -0,0 +1,3 @@ +:root { + font-family: sans-serif; +} diff --git a/public/index.html b/public/index.html index f5f3550..0472aff 100644 --- a/public/index.html +++ b/public/index.html @@ -13,10 +13,15 @@

Current Status of db:

List of songs in the database:

-