From 00550cca852fe7433a8257aa9de7686238ff8ab1 Mon Sep 17 00:00:00 2001
From: Kristy Fournier <124598538+kristy-fournier@users.noreply.github.com>
Date: Mon, 26 Jan 2026 10:39:17 -0500
Subject: [PATCH] I got distracted and broke something but the responses should
be good now
---
Client/scripts.js | 25 +++++++++++++++++--------
Server/webbyBits.py | 9 +++++----
2 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/Client/scripts.js b/Client/scripts.js
index 8f556be..9ecb8a8 100644
--- a/Client/scripts.js
+++ b/Client/scripts.js
@@ -2,7 +2,7 @@
let ip;
let alertTime = 2;
let adminPass = "";
-const ERR_NO_ADMIN = 401; // gonna use this later to refactor
+const ERR_NO_ADMIN = 401;
const VALID_FILE_EXT = ["mp3","flac","wav"];
const params = new URLSearchParams(location.search);
@@ -54,12 +54,15 @@ async function getFromServer(bodyInfo, source="",password=adminPass) {
// it is easy which i like
// and it overrides any other non-async alerts which is nice
alertText("Error: Admin restricted action")
+ } else if(response.status !== 200){
+ alertText("Error: "+data.error);
}
+ data["status"] = response.status;
return await data;
} catch(e) {
console.log("error print here:");
console.log(e);
- if (e.contains("TypeError: Failed to fetch")){
+ if (e == "TypeError: Failed to fetch"){
alertText("Error: Can't Connect to Server (is the ip set?)")
} else {
alertText("Error: " + e);
@@ -87,6 +90,8 @@ function getCookie(cname) {
return "";
}
//someone more organised than me would have set all these html elements to variables so they dont have to get them 50 times
+// also someone who likes things not being dumb more than me would have separated the client and server buttons
+let timer = null;
async function controlButton(buttonType) {
if (buttonType == "pp") { // Play-Pause button
getFromServer({control: "play-pause"}, "controls")
@@ -101,6 +106,9 @@ async function controlButton(buttonType) {
document.getElementById("playlist-mode").style.display = "block";
document.getElementById("songlist-mode").style.display = "none";
document.getElementById("settings-mode").style.display = "none";
+ timer = setInterval(() => {
+
+ })
generateVisualPlaylist();
} else if (buttonType == "se") { //SearchMode button
document.getElementById("songlist").innerHTML = "
Search to find songs!
";
@@ -246,7 +254,8 @@ async function checkSettings(skipServer=false) {
}
}
//ping the server here
- x = await getFromServer({setting: "getsettings"}, "settings");
+ data = await getFromServer({setting: "getsettings"}, "settings");
+ x = data["data"];
if (!(skipServer) || partyButtonState=="N/A") {
if (x["partymode"] == false) {
document.getElementById("partymode-button").innerHTML = "Off";
@@ -271,7 +280,8 @@ async function checkSettings(skipServer=false) {
async function generateVisualPlaylist(conditions="") {
document.getElementById("playlist").innerHTML = "";
- playlist = await getFromServer(null, "playlist");
+ data = await getFromServer(null, "playlist");
+ playlist = data["data"];
playlist = Object.values(playlist).map(obj => {
const filename = Object.keys(obj)[0]; // Get the filename
const songData = obj[filename]; // Get the song metadata
@@ -446,18 +456,17 @@ document.getElementById("volumerange").onchange = async function() {
// there is no reason for this not to be a defined function
// FIX THIS
let returnValue = await getFromServer({setting:"volume",level:this.value}, "settings")
- if (returnValue == ERR_NO_ADMIN) {
+ if (returnValue["status"] == ERR_NO_ADMIN) {
// alertText("Error: Admin restricted action");
// there's an admin restrict alert built into getFromServer
// i wanna put the volume slider back to where it was but idk a good way to keep the previous volume
checkSettings(false);
- } else if (returnValue["volumePassed"] !=0) {
+ } else if (returnValue["data"]["volumePassed"] !=0) {
// i forgot about this, i had to do this because it confused the crap out of me one time
// vlc doesn't let you change the volume of nothing, which makes sense if you think about it
alertText("Nothing is playing")
document.getElementById("volumerange").value = -1
- }
- else if (this.value == 0) {
+ } else if (this.value == 0) {
alertText("The volume is now set to 0 (Pause?)")
} else {
alertText("The volume is now set to " + this.value.toString())
diff --git a/Server/webbyBits.py b/Server/webbyBits.py
index 65cd09a..a506e82 100644
--- a/Server/webbyBits.py
+++ b/Server/webbyBits.py
@@ -143,11 +143,12 @@ def settingsControl():
recieveData = request.get_json(force=True)
if recieveData["setting"] == "volume":
if ADMIN_PASS == recieveData['password'] or controlPerms["VOL"]:
- if(recieveData["level"] <= 100 and recieveData["level"] >= 0):
- volumePassed = player.audio_set_volume(int(recieveData["level"]))
+ volumeLevel = int(recieveData["level"])
+ if(volumeLevel <= 100 and volumeLevel >= 0):
+ volumePassed = player.audio_set_volume(volumeLevel)
return {"error":"ok","data":{"volumePassed":volumePassed}},200
else:
- return {"error":"Invalid volume level","data":None}
+ return {"error":"Invalid volume level","data":None},422
else:
return ERR_NO_ADMIN
elif recieveData["setting"] == "partymode-toggle":
@@ -166,7 +167,7 @@ def settingsControl():
# probably should have made this a different request type or something but it works
return {"error":"ok","data":{"partymode":partyMode,"volume":player.audio_get_volume(),"admin":controlPerms}},200
else:
- return {"error":"Not a valid setting","data":None},400
+ return {"error":"Not a valid setting","data":None},422
@app.route("/search", methods=['POST'])
def searchSongDB():