python3 ./testing/dummy_testing_data.py
# now we can run the main app with the right arguments
go build .
- ./songmanager -port 8000 -binb_location="" -songs_location="" -redis_location="localhost:6379" -container_name=""
+ ./songmanager -port 8000 -binb_location="" -songs_location="./testing/songs/" -redis_location="localhost:6379" -container_name=""
mainLogger.Println("Given container_name:", *paramContainerName)
- DBwrapper := dbhandling.NewDbWrapper(*paramRedisLocation)
+ DBwrapper := dbhandling.NewDbWrapper(*paramRedisLocation, *paramSongsLocation)
// Setting up the routing
mux := http.NewServeMux()
mux.HandleFunc("/api/db_status_update", DBwrapper.GetDBStatus)
+ mux.HandleFunc("/api/renameSong", DBwrapper.UpdateSongsFilename)
mux.HandleFunc("/api/updateSong", DBwrapper.UpdateSongStats)
mux.Handle("/", http.FileServer(http.Dir("./public/")))
"context"
"encoding/json"
"net/http"
+ "os"
+ "path/filepath"
"github.com/redis/go-redis/v9"
)
DisplayTrackName string
}
+type DBUpdateSongName struct {
+ Key string
+ NewFilename string
+}
+
type DBRoom struct {
Name string
AssignedSongKeys []string
type DBWrapper struct {
RedisDb *redis.Client
ctx context.Context
+ PathToSongs string
}
-func NewDbWrapper(redisLocation string) DBWrapper {
+func NewDbWrapper(redisLocation string, songsLocation string) DBWrapper {
return DBWrapper {
redis.NewClient(&redis.Options{
Addr: redisLocation,
Protocol: 2,
}),
context.Background(),
+ songsLocation,
}
}
w.WriteHeader(http.StatusOK)
}
+func (dbw *DBWrapper) UpdateSongsFilename(w http.ResponseWriter, r *http.Request) {
+ if r.Method != "POST" {
+ w.WriteHeader(http.StatusMethodNotAllowed)
+ return
+ }
+
+ changeFilename := DBUpdateSongName{}
+ err := json.NewDecoder(r.Body).Decode(&changeFilename)
+ if err != nil {
+ panic(err)
+ }
+
+ intf, err := dbw.RedisDb.HMGet(dbw.ctx, changeFilename.Key, "previewUrl").Result()
+ if err != nil {
+ panic(err)
+ }
+
+ err = os.Rename(
+ filepath.Join(dbw.PathToSongs, intf[0].(string)),
+ filepath.Join(dbw.PathToSongs, changeFilename.NewFilename),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ _, err = dbw.RedisDb.HMSet(dbw.ctx, changeFilename.Key, map[string]interface{}{
+ "previewUrl": changeFilename.NewFilename,
+ }).Result()
+ if err != nil {
+ panic(err)
+ }
+
+ w.WriteHeader(http.StatusOK)
+}
+
func (dbw *DBWrapper) GetDBStatus(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
w.WriteHeader(http.StatusMethodNotAllowed)
<p>Preview URL (which song file)</p>
<input id="editPreviewUrl" pattern="[a-zA-Z0-9~\!]" type="text"></input>
+ <button id="updateSongFile">Directly Rename Song File</button>
<p>Artwork URL 60</p>
<input id="editArtworkUrl60" pattern="[a-zA-Z0-9~\!]" type="text"></input>
let editElement = document.getElementById("editElement")
+let updateSongFile = document.getElementById("updateSongFile")
let editArtistName = document.getElementById("editArtistName")
let editTrackName = document.getElementById("editTrackName")
let editTrackViewUrl = document.getElementById("editTrackViewUrl")
let editDisplayArtistNames = document.getElementById("editDisplayArtistNames")
let editDisplayTrackName = document.getElementById("editDisplayTrackName")
+updateSongFile.onclick = (event) => { sendUpdateSongName(event) }
function getSongUsingKey(key) {
for (let song of AllSongs) {
editArtworkUrl100.value = song.ArtworkURL100
editDisplayArtistNames.value = song.DisplayArtistNames
editDisplayTrackName.value = song.DisplayTrackName
+
+ updateSongFile.className = song.Key
}
function closeEditElement() {
openEditElement(song)
}
+async function sendUpdateSongName(event) {
+ let key = event.srcElement.className
+ let NewFilename = editPreviewUrl.value
+ console.log("updating song name")
+ console.log(key, NewFilename)
+
+ await fetch("/api/renameSong", {
+ method: "POST",
+ body: JSON.stringify({
+ Key: key,
+ NewFilename: NewFilename
+ })
+ })
+
+ get_updated_status()
+}
+
function newSongDisplayWithEdit(song) {
let wrap = document.createElement("div")
wrap.id = "key=" + song.Key
// update list of rooms
let room_list = document.getElementById("list_of_rooms")
+ room_list.innerHTML = ""
+
for (let room of body.Rooms) {
let header = document.createElement("h3")
header.innerText = room.Name
"artistName": line[0],
"trackName": line[2],
"trackViewUrl": "http:///somehwere",
- "previewUrl": "http://somewhere",
+ "previewUrl": line[4],
"artworkUrl60": "http://somewhere",
"artworkUrl100": "http://somewhere",
"displayArtistNames": line[1],
"displayTrackName": line[3],
})
+ f = open(f"./testing/songs/{line[4]}", "w+")
+ f.close()
r.zadd("hits", {i: i})
# 'song:' + i,