I got distracted and broke something but the responses should be good now
This commit is contained in:
parent
0b64a6f297
commit
00550cca85
2 changed files with 22 additions and 12 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
let ip;
|
let ip;
|
||||||
let alertTime = 2;
|
let alertTime = 2;
|
||||||
let adminPass = "";
|
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 VALID_FILE_EXT = ["mp3","flac","wav"];
|
||||||
|
|
||||||
const params = new URLSearchParams(location.search);
|
const params = new URLSearchParams(location.search);
|
||||||
|
|
@ -54,12 +54,15 @@ async function getFromServer(bodyInfo, source="",password=adminPass) {
|
||||||
// it is easy which i like
|
// it is easy which i like
|
||||||
// and it overrides any other non-async alerts which is nice
|
// and it overrides any other non-async alerts which is nice
|
||||||
alertText("Error: Admin restricted action")
|
alertText("Error: Admin restricted action")
|
||||||
|
} else if(response.status !== 200){
|
||||||
|
alertText("Error: "+data.error);
|
||||||
}
|
}
|
||||||
|
data["status"] = response.status;
|
||||||
return await data;
|
return await data;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log("error print here:");
|
console.log("error print here:");
|
||||||
console.log(e);
|
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?)")
|
alertText("Error: Can't Connect to Server (is the ip set?)")
|
||||||
} else {
|
} else {
|
||||||
alertText("Error: " + e);
|
alertText("Error: " + e);
|
||||||
|
|
@ -87,6 +90,8 @@ function getCookie(cname) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
//someone more organised than me would have set all these html elements to variables so they dont have to get them 50 times
|
//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) {
|
async function controlButton(buttonType) {
|
||||||
if (buttonType == "pp") { // Play-Pause button
|
if (buttonType == "pp") { // Play-Pause button
|
||||||
getFromServer({control: "play-pause"}, "controls")
|
getFromServer({control: "play-pause"}, "controls")
|
||||||
|
|
@ -101,6 +106,9 @@ async function controlButton(buttonType) {
|
||||||
document.getElementById("playlist-mode").style.display = "block";
|
document.getElementById("playlist-mode").style.display = "block";
|
||||||
document.getElementById("songlist-mode").style.display = "none";
|
document.getElementById("songlist-mode").style.display = "none";
|
||||||
document.getElementById("settings-mode").style.display = "none";
|
document.getElementById("settings-mode").style.display = "none";
|
||||||
|
timer = setInterval(() => {
|
||||||
|
|
||||||
|
})
|
||||||
generateVisualPlaylist();
|
generateVisualPlaylist();
|
||||||
} else if (buttonType == "se") { //SearchMode button
|
} else if (buttonType == "se") { //SearchMode button
|
||||||
document.getElementById("songlist").innerHTML = "<h1>Search to find songs!</h1>";
|
document.getElementById("songlist").innerHTML = "<h1>Search to find songs!</h1>";
|
||||||
|
|
@ -246,7 +254,8 @@ async function checkSettings(skipServer=false) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//ping the server here
|
//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 (!(skipServer) || partyButtonState=="N/A") {
|
||||||
if (x["partymode"] == false) {
|
if (x["partymode"] == false) {
|
||||||
document.getElementById("partymode-button").innerHTML = "Off";
|
document.getElementById("partymode-button").innerHTML = "Off";
|
||||||
|
|
@ -271,7 +280,8 @@ async function checkSettings(skipServer=false) {
|
||||||
|
|
||||||
async function generateVisualPlaylist(conditions="") {
|
async function generateVisualPlaylist(conditions="") {
|
||||||
document.getElementById("playlist").innerHTML = "<h1 id=\"playlist-alert\"></h1>";
|
document.getElementById("playlist").innerHTML = "<h1 id=\"playlist-alert\"></h1>";
|
||||||
playlist = await getFromServer(null, "playlist");
|
data = await getFromServer(null, "playlist");
|
||||||
|
playlist = data["data"];
|
||||||
playlist = Object.values(playlist).map(obj => {
|
playlist = Object.values(playlist).map(obj => {
|
||||||
const filename = Object.keys(obj)[0]; // Get the filename
|
const filename = Object.keys(obj)[0]; // Get the filename
|
||||||
const songData = obj[filename]; // Get the song metadata
|
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
|
// there is no reason for this not to be a defined function
|
||||||
// FIX THIS
|
// FIX THIS
|
||||||
let returnValue = await getFromServer({setting:"volume",level:this.value}, "settings")
|
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");
|
// alertText("Error: Admin restricted action");
|
||||||
// there's an admin restrict alert built into getFromServer
|
// 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
|
// i wanna put the volume slider back to where it was but idk a good way to keep the previous volume
|
||||||
checkSettings(false);
|
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
|
// 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
|
// vlc doesn't let you change the volume of nothing, which makes sense if you think about it
|
||||||
alertText("Nothing is playing")
|
alertText("Nothing is playing")
|
||||||
document.getElementById("volumerange").value = -1
|
document.getElementById("volumerange").value = -1
|
||||||
}
|
} else if (this.value == 0) {
|
||||||
else if (this.value == 0) {
|
|
||||||
alertText("The volume is now set to 0 (Pause?)")
|
alertText("The volume is now set to 0 (Pause?)")
|
||||||
} else {
|
} else {
|
||||||
alertText("The volume is now set to " + this.value.toString())
|
alertText("The volume is now set to " + this.value.toString())
|
||||||
|
|
|
||||||
|
|
@ -143,11 +143,12 @@ def settingsControl():
|
||||||
recieveData = request.get_json(force=True)
|
recieveData = request.get_json(force=True)
|
||||||
if recieveData["setting"] == "volume":
|
if recieveData["setting"] == "volume":
|
||||||
if ADMIN_PASS == recieveData['password'] or controlPerms["VOL"]:
|
if ADMIN_PASS == recieveData['password'] or controlPerms["VOL"]:
|
||||||
if(recieveData["level"] <= 100 and recieveData["level"] >= 0):
|
volumeLevel = int(recieveData["level"])
|
||||||
volumePassed = player.audio_set_volume(int(recieveData["level"]))
|
if(volumeLevel <= 100 and volumeLevel >= 0):
|
||||||
|
volumePassed = player.audio_set_volume(volumeLevel)
|
||||||
return {"error":"ok","data":{"volumePassed":volumePassed}},200
|
return {"error":"ok","data":{"volumePassed":volumePassed}},200
|
||||||
else:
|
else:
|
||||||
return {"error":"Invalid volume level","data":None}
|
return {"error":"Invalid volume level","data":None},422
|
||||||
else:
|
else:
|
||||||
return ERR_NO_ADMIN
|
return ERR_NO_ADMIN
|
||||||
elif recieveData["setting"] == "partymode-toggle":
|
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
|
# 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
|
return {"error":"ok","data":{"partymode":partyMode,"volume":player.audio_get_volume(),"admin":controlPerms}},200
|
||||||
else:
|
else:
|
||||||
return {"error":"Not a valid setting","data":None},400
|
return {"error":"Not a valid setting","data":None},422
|
||||||
|
|
||||||
@app.route("/search", methods=['POST'])
|
@app.route("/search", methods=['POST'])
|
||||||
def searchSongDB():
|
def searchSongDB():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue