Admin mode #5
2 changed files with 40 additions and 18 deletions
|
|
@ -222,6 +222,16 @@ async function checkSettings(skipServer=false) {
|
||||||
document.getElementById("partymode-button").innerHTML = "Off";
|
document.getElementById("partymode-button").innerHTML = "Off";
|
||||||
}
|
}
|
||||||
document.getElementById("volumerange").value = parseInt(x["volume"])
|
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"];
|
||||||
|
document.getElementById("playpausesettingcheckbox").checked = currentAdminPerms["PP"];
|
||||||
|
document.getElementById("partymodesettingcheckbox").checked = currentAdminPerms["PM"];
|
||||||
|
document.getElementById("volumechangesettingcheckbox").checked = currentAdminPerms["VOL"];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function generateVisualPlaylist(conditions="") {
|
async function generateVisualPlaylist(conditions="") {
|
||||||
|
|
@ -325,14 +335,20 @@ function adminPassEnter(e) {
|
||||||
alertText("Admin Password Updated")
|
alertText("Admin Password Updated")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function submitPerms() {
|
async function submitPerms() {
|
||||||
let tempData = {}
|
let tempData = {}
|
||||||
tempData["PP"] = document.getElementById("playpausesettingcheckbox").checked
|
tempData["PP"] = document.getElementById("playpausesettingcheckbox").checked;
|
||||||
tempData["SK"] = document.getElementById("skipsongsettingcheckbox").checked
|
tempData["SK"] = document.getElementById("skipsongsettingcheckbox").checked;
|
||||||
tempData["AS"] = document.getElementById("addsongsettingcheckbox").checked
|
tempData["AS"] = document.getElementById("addsongsettingcheckbox").checked;
|
||||||
tempData["PM"] = document.getElementById("partymodesettingcheckbox").checked
|
tempData["PM"] = document.getElementById("partymodesettingcheckbox").checked;
|
||||||
tempData["VOL"] = document.getElementById("partymodesettingcheckbox").checked
|
tempData["VOL"] = document.getElementById("partymodesettingcheckbox").checked;
|
||||||
getFromServer({"setting":"perms","admin":tempData},"settings")
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let optionslist = []
|
let optionslist = []
|
||||||
|
|
@ -350,6 +366,8 @@ document.getElementById("settings-mode").style.display = "none";
|
||||||
document.getElementById("volumerange").onchange = async function() {
|
document.getElementById("volumerange").onchange = async function() {
|
||||||
let returnValue = await getFromServer({setting:"volume",level:this.value}, "settings")
|
let returnValue = await getFromServer({setting:"volume",level:this.value}, "settings")
|
||||||
if (returnValue["volumePassed"] !=0) {
|
if (returnValue["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")
|
alertText("Nothing is playing")
|
||||||
document.getElementById("volumerange").value = -1
|
document.getElementById("volumerange").value = -1
|
||||||
}
|
}
|
||||||
|
|
@ -378,6 +396,7 @@ document.getElementById("songlist").addEventListener('click', function(e){checkW
|
||||||
let tempWidth = document.getElementById('controls').clientWidth;
|
let tempWidth = document.getElementById('controls').clientWidth;
|
||||||
document.getElementById("controls").style.marginLeft = "-"+String(parseInt(tempWidth/2))+"px";
|
document.getElementById("controls").style.marginLeft = "-"+String(parseInt(tempWidth/2))+"px";
|
||||||
// document.getElementById("darkmode-button").addEventListener('click',function(){toggleDark()})
|
// document.getElementById("darkmode-button").addEventListener('click',function(){toggleDark()})
|
||||||
|
|
||||||
//for my use case (my immediate family), they dont know how to set an ip
|
//for my use case (my immediate family), they dont know how to set an ip
|
||||||
//using this allows the creator of the link for, a qr code for example, to set the ip before distributing the code, and it would all work smoothly
|
//using this allows the creator of the link for, a qr code for example, to set the ip before distributing the code, and it would all work smoothly
|
||||||
//example (http://192.168.1.100:8000/?ip=192.168.1.100:19054 sets the ip to the same host at the default port)
|
//example (http://192.168.1.100:8000/?ip=192.168.1.100:19054 sets the ip to the same host at the default port)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,11 @@ parser=argparse.ArgumentParser(description="Options for the Webby Bits")
|
||||||
parser.add_argument('-p','--port',help="Port to host on, not the same as the web (client) port",default='19054')
|
parser.add_argument('-p','--port',help="Port to host on, not the same as the web (client) port",default='19054')
|
||||||
parser.add_argument('-a','--admin',help="Add an admin password to be used in the client. DO NOT use a password you use elsewhere",default="")
|
parser.add_argument('-a','--admin',help="Add an admin password to be used in the client. DO NOT use a password you use elsewhere",default="")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
portTheUserPicked=args.port
|
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
|
||||||
ADMIN_PASS = args.admin
|
ADMIN_PASS = args.admin
|
||||||
if not(ADMIN_PASS):
|
if not(ADMIN_PASS):
|
||||||
ADMIN_PASS = None
|
ADMIN_PASS = None
|
||||||
|
|
@ -36,7 +40,7 @@ elif "/" in soundLocation:
|
||||||
soundLocation += "/"
|
soundLocation += "/"
|
||||||
else:
|
else:
|
||||||
soundLocation += "\\"
|
soundLocation += "\\"
|
||||||
print(soundLocation)
|
#print(soundLocation)
|
||||||
#Create Virtual table for searching
|
#Create Virtual table for searching
|
||||||
songDatabase.execute("DROP TABLE virtualSongs;")
|
songDatabase.execute("DROP TABLE virtualSongs;")
|
||||||
songDatabase.execute("CREATE VIRTUAL TABLE virtualSongs USING fts5(filename, title, artist, art, length);")
|
songDatabase.execute("CREATE VIRTUAL TABLE virtualSongs USING fts5(filename, title, artist, art, length);")
|
||||||
|
|
@ -58,7 +62,7 @@ player = fakeplayer.media_player_new()
|
||||||
# for client side volume to work as well as possible, set system volume to 100 and control in app
|
# for client side volume to work as well as possible, set system volume to 100 and control in app
|
||||||
player.audio_set_volume(100)
|
player.audio_set_volume(100)
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
# because you are posting from another domain to this one, you need CORS
|
# because you are POSTing from another domain to this one, you need CORS
|
||||||
CORS(app)
|
CORS(app)
|
||||||
|
|
||||||
def queueSong(song):
|
def queueSong(song):
|
||||||
|
|
@ -124,6 +128,8 @@ def playerControls():
|
||||||
return "401"
|
return "401"
|
||||||
else:
|
else:
|
||||||
return "400"
|
return "400"
|
||||||
|
else:
|
||||||
|
return "400"
|
||||||
|
|
||||||
@app.route("/settings", methods=['POST'])
|
@app.route("/settings", methods=['POST'])
|
||||||
def settingsControl():
|
def settingsControl():
|
||||||
|
|
@ -145,8 +151,8 @@ def settingsControl():
|
||||||
else:
|
else:
|
||||||
return "401"
|
return "401"
|
||||||
elif recieveData["setting"] == "perms":
|
elif recieveData["setting"] == "perms":
|
||||||
print(ADMIN_PASS)
|
# print(ADMIN_PASS)
|
||||||
print(recieveData["password"])
|
# print(recieveData["password"])
|
||||||
if ADMIN_PASS == recieveData["password"] and ADMIN_PASS:
|
if ADMIN_PASS == recieveData["password"] and ADMIN_PASS:
|
||||||
#if an adminpass doesn't exist these perms can never be changed
|
#if an adminpass doesn't exist these perms can never be changed
|
||||||
controlPerms = recieveData["admin"]
|
controlPerms = recieveData["admin"]
|
||||||
|
|
@ -188,17 +194,14 @@ def searchSongDB():
|
||||||
@app.route("/songadd", methods=["POST"])
|
@app.route("/songadd", methods=["POST"])
|
||||||
def songadd():
|
def songadd():
|
||||||
recieveData=request.get_json(force=True)
|
recieveData=request.get_json(force=True)
|
||||||
if ADMIN_PASS and ADMIN_PASS == recieveData['password']:
|
if (ADMIN_PASS and ADMIN_PASS == recieveData['password']):
|
||||||
# Pass exists and is correct
|
# Pass exists and is correct, or it's not restricted
|
||||||
queueSong(recieveData['song'])
|
queueSong(recieveData['song'])
|
||||||
return "200"
|
return "200"
|
||||||
elif ADMIN_PASS and not(controlPerms["AS"]):
|
else:
|
||||||
# Pass exists, or this action isn't restricted
|
# Pass exists, or this action isn't restricted
|
||||||
return "401"
|
return "401"
|
||||||
else:
|
|
||||||
# No pass
|
|
||||||
queueSong(recieveData['song'])
|
|
||||||
return "200"
|
|
||||||
@app.route("/playlist", methods=["POST"])
|
@app.route("/playlist", methods=["POST"])
|
||||||
def getPlaylist():
|
def getPlaylist():
|
||||||
global songNext
|
global songNext
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue