Admin mode #5
3 changed files with 35 additions and 21 deletions
|
|
@ -1,6 +1,8 @@
|
|||
let ip;
|
||||
let alertTime = 2;
|
||||
let adminPass = "";
|
||||
const ERR_NO_ADMIN = "401"; // gonna use this later to refactor
|
||||
|
||||
async function alertText(text="Song Added!") {
|
||||
alertbox = document.getElementById("alert");
|
||||
alertbox.innerHTML = text;
|
||||
|
|
@ -25,12 +27,12 @@ async function getFromServer(bodyInfo, source="",password=adminPass) {
|
|||
});
|
||||
const data = await response.json();
|
||||
if (data == "401") {
|
||||
alertText("error: Admin restricted action")
|
||||
alertText("Error: Admin restricted action")
|
||||
}
|
||||
return await data;
|
||||
} catch(e) {
|
||||
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 if(e == "") {
|
||||
|
||||
} else {
|
||||
|
|
@ -224,8 +226,6 @@ async function checkSettings(skipServer=false) {
|
|||
document.getElementById("volumerange").value = parseInt(x["volume"])
|
||||
|
||||
// do the admin checkboxes here
|
||||
// seemingly i almost finished it last time, dunno why i stopped here
|
||||
// like as far as i can tell this is the last step
|
||||
let currentAdminPerms = x["admin"];
|
||||
document.getElementById("addsongsettingcheckbox").checked = currentAdminPerms["AS"];
|
||||
document.getElementById("skipsongsettingcheckbox").checked = currentAdminPerms["SK"];
|
||||
|
|
@ -302,8 +302,12 @@ async function generateVisualPlaylist(conditions="") {
|
|||
}
|
||||
|
||||
async function submitSong(songid) {
|
||||
getFromServer({song: songid}, "songadd")
|
||||
alertText("Added to Queue")
|
||||
let returncode = await getFromServer({song: songid}, "songadd");
|
||||
if(returncode == ERR_NO_ADMIN) {
|
||||
// right now the error is alerted in getFromServer, maybe will change that
|
||||
} else {
|
||||
alertText("Added to Queue");
|
||||
}
|
||||
}
|
||||
function checkWhatSongWasClicked(e) {
|
||||
itemId = e.srcElement.id;
|
||||
|
|
@ -335,7 +339,7 @@ function adminPassEnter(e) {
|
|||
alertText("Admin Password Updated")
|
||||
}
|
||||
}
|
||||
async function submitPerms() {
|
||||
async function submitPerms(e) {
|
||||
let tempData = {}
|
||||
tempData["PP"] = document.getElementById("playpausesettingcheckbox").checked;
|
||||
tempData["SK"] = document.getElementById("skipsongsettingcheckbox").checked;
|
||||
|
|
@ -343,11 +347,11 @@ async function submitPerms() {
|
|||
tempData["PM"] = document.getElementById("partymodesettingcheckbox").checked;
|
||||
tempData["VOL"] = document.getElementById("partymodesettingcheckbox").checked;
|
||||
let returncode = await getFromServer({"setting":"perms","admin":tempData},"settings");
|
||||
if (returncode === "401") {
|
||||
// just so that the checkboxes don't change if you click without the
|
||||
// (I know i could do this better but this is good enough for now)
|
||||
// okay this actually doesn't work but i have to go eat dinner
|
||||
checkSettings();
|
||||
if (returncode == ERR_NO_ADMIN) {
|
||||
// if you aren't allowed to check the box then toggle it again
|
||||
// its not perfect if you spam click, but it gets the point across to the user
|
||||
let clickedBox = e.srcElement;
|
||||
clickedBox.checked = !clickedBox.checked;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -388,7 +392,7 @@ document.getElementById("songsearch").addEventListener('keydown', function(e){se
|
|||
document.getElementById("iptextbox").addEventListener('keydown', function(e){ipSetEnter(e)});
|
||||
document.getElementById("alerttimetextbox").addEventListener('keydown', function(e){alertTimeEnter(e)});
|
||||
document.getElementById("adminpasswordbox").addEventListener('keydown',function(e){adminPassEnter(e)});
|
||||
document.getElementById("admincheckholder").addEventListener('click',function(){submitPerms()});
|
||||
document.getElementById("admincheckholder").addEventListener('click',function(e){submitPerms(e)});
|
||||
document.getElementById("partymode-button").addEventListener('click',function(){controlButton("pm")})
|
||||
//sets the fact that clicking a song needs to return its id to the function to find it
|
||||
document.getElementById("songlist").addEventListener('click', function(e){checkWhatSongWasClicked(e)});
|
||||
|
|
|
|||
|
|
@ -177,6 +177,14 @@ h4 {
|
|||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.settings > .item > h2 {
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.settings > .item > p {
|
||||
margin-top: 0px
|
||||
}
|
||||
|
||||
.versionNumber {
|
||||
font-size: 8px;
|
||||
font-style: italic;
|
||||
|
|
|
|||
|
|
@ -13,8 +13,10 @@ args = parser.parse_args()
|
|||
|
||||
|
||||
portTheUserPicked=args.port
|
||||
#Just a note that the return code "401" as of now is used to mean "you don't have the password"
|
||||
#This is not great design, and the whole "returning string codes" thing is something to add to the todo list
|
||||
# Just a note that the return code "401" as of now is used to mean "you don't have the password"
|
||||
# This is not great design, and the whole "returning string codes" thing is something to add to the todo list
|
||||
# I mean returning 200 when no return is necesary i think is fine but we'll see
|
||||
ERR_NO_ADMIN = "401"
|
||||
ADMIN_PASS = args.admin
|
||||
if not(ADMIN_PASS):
|
||||
ADMIN_PASS = None
|
||||
|
|
@ -119,13 +121,13 @@ def playerControls():
|
|||
player.pause()
|
||||
return "200"
|
||||
else:
|
||||
return "401"
|
||||
return ERR_NO_ADMIN
|
||||
elif recieveData["control"] == "skip":
|
||||
if ADMIN_PASS == recieveData['password'] or not(ADMIN_PASS) or controlPerms["SK"]:
|
||||
skipNow = True
|
||||
return "200"
|
||||
else:
|
||||
return "401"
|
||||
return ERR_NO_ADMIN
|
||||
else:
|
||||
return "400"
|
||||
else:
|
||||
|
|
@ -143,13 +145,13 @@ def settingsControl():
|
|||
volumePassed = player.audio_set_volume(int(recieveData["level"]))
|
||||
return {"volumePassed":volumePassed}
|
||||
else:
|
||||
return "401"
|
||||
return ERR_NO_ADMIN
|
||||
elif recieveData["setting"] == "partymode-toggle":
|
||||
if ADMIN_PASS == recieveData['password'] or not(ADMIN_PASS) or controlPerms["PM"]:
|
||||
partyMode = not(partyMode)
|
||||
return "200"
|
||||
else:
|
||||
return "401"
|
||||
return ERR_NO_ADMIN
|
||||
elif recieveData["setting"] == "perms":
|
||||
# print(ADMIN_PASS)
|
||||
# print(recieveData["password"])
|
||||
|
|
@ -158,7 +160,7 @@ def settingsControl():
|
|||
controlPerms = recieveData["admin"]
|
||||
return "200"
|
||||
else:
|
||||
return "401"
|
||||
return ERR_NO_ADMIN
|
||||
elif recieveData["setting"] == "getsettings":
|
||||
# probably should have made this a different request type or something but it works
|
||||
x = {"partymode":partyMode,"volume":player.audio_get_volume(),"admin":controlPerms}
|
||||
|
|
@ -200,7 +202,7 @@ def songadd():
|
|||
return "200"
|
||||
else:
|
||||
# Pass exists, or this action isn't restricted
|
||||
return "401"
|
||||
return ERR_NO_ADMIN
|
||||
|
||||
@app.route("/playlist", methods=["POST"])
|
||||
def getPlaylist():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue