Fixed a bunch of bugs to make adminpass complete
also added a bunch of comments and a new item design (css) that i'm probably going to undo
This commit is contained in:
parent
d72320aae4
commit
e08e9cbcca
4 changed files with 38 additions and 18 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
// set all the global stuff
|
||||||
let ip;
|
let ip;
|
||||||
let alertTime = 2;
|
let alertTime = 2;
|
||||||
let adminPass = "";
|
let adminPass = "";
|
||||||
|
|
@ -26,7 +27,11 @@ async function getFromServer(bodyInfo, source="",password=adminPass) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (data == "401") {
|
if (data == ERR_NO_ADMIN) {
|
||||||
|
// im suprised i didn't comment on this already but this is kinda lame desing
|
||||||
|
// its not wrong but you know
|
||||||
|
// it is easy which i like
|
||||||
|
// and it overrides any other non-async alerts which is nice
|
||||||
alertText("Error: Admin restricted action")
|
alertText("Error: Admin restricted action")
|
||||||
}
|
}
|
||||||
return await data;
|
return await data;
|
||||||
|
|
@ -36,14 +41,13 @@ async function getFromServer(bodyInfo, source="",password=adminPass) {
|
||||||
} else if(e == "") {
|
} else if(e == "") {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
alertText("error: " + e)
|
alertText("Error: " + e)
|
||||||
}
|
}
|
||||||
const response=null;
|
const response=null;
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//cookie reader is taken from internet because cookies ae too complicated for me
|
//cookie reader is taken from internet because cookies ae too complicated for me
|
||||||
//i still understand how it works though promise just i see no reason to write this from scratch
|
//i still understand how it works though promise just i see no reason to write this from scratch
|
||||||
function getCookie(cname) {
|
function getCookie(cname) {
|
||||||
|
|
@ -63,34 +67,34 @@ function getCookie(cname) {
|
||||||
}
|
}
|
||||||
//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
|
||||||
async function controlButton(buttonType) {
|
async function controlButton(buttonType) {
|
||||||
if (buttonType == "pp") {
|
if (buttonType == "pp") { // Play-Pause button
|
||||||
getFromServer({control: "play-pause"}, "controls")
|
getFromServer({control: "play-pause"}, "controls")
|
||||||
} else if (buttonType == "sk") {
|
} else if (buttonType == "sk") { // Skip button
|
||||||
getFromServer({control: "skip"}, "controls")
|
getFromServer({control: "skip"}, "controls")
|
||||||
if (document.getElementById("playlist-mode").style.display == "block") {
|
if (document.getElementById("playlist-mode").style.display == "block") {
|
||||||
generateVisualPlaylist("skip-button");
|
generateVisualPlaylist("skip-button");
|
||||||
}
|
}
|
||||||
} else if (buttonType == "pl") {
|
} else if (buttonType == "pl") { // Playlist button
|
||||||
document.getElementById("songlist").innerHTML = "";
|
document.getElementById("songlist").innerHTML = "";
|
||||||
document.getElementById("playlist").innerHTML = "<h1 id=\"playlist-alert\"></h1>";
|
document.getElementById("playlist").innerHTML = "<h1 id=\"playlist-alert\"></h1>";
|
||||||
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";
|
||||||
generateVisualPlaylist();
|
generateVisualPlaylist();
|
||||||
} else if (buttonType == "se") {
|
} 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>";
|
||||||
document.getElementById("playlist").innerHTML = "";
|
document.getElementById("playlist").innerHTML = "";
|
||||||
document.getElementById("playlist-mode").style.display = "none";
|
document.getElementById("playlist-mode").style.display = "none";
|
||||||
document.getElementById("songlist-mode").style.display = "block";
|
document.getElementById("songlist-mode").style.display = "block";
|
||||||
document.getElementById("settings-mode").style.display = "none";
|
document.getElementById("settings-mode").style.display = "none";
|
||||||
} else if (buttonType == "st") {
|
} else if (buttonType == "st") { //Settings button
|
||||||
document.getElementById("songlist").innerHTML = "";
|
document.getElementById("songlist").innerHTML = "";
|
||||||
document.getElementById("playlist").innerHTML = "";
|
document.getElementById("playlist").innerHTML = "";
|
||||||
document.getElementById("playlist-mode").style.display = "none";
|
document.getElementById("playlist-mode").style.display = "none";
|
||||||
document.getElementById("songlist-mode").style.display = "none";
|
document.getElementById("songlist-mode").style.display = "none";
|
||||||
document.getElementById("settings-mode").style.display = "block";
|
document.getElementById("settings-mode").style.display = "block";
|
||||||
checkSettings()
|
checkSettings()
|
||||||
} else if (buttonType = "pm") {
|
} else if (buttonType = "pm") { //Partymode toggle (in settings)
|
||||||
await getFromServer({setting: "partymode-toggle"}, "settings")
|
await getFromServer({setting: "partymode-toggle"}, "settings")
|
||||||
checkSettings(true)
|
checkSettings(true)
|
||||||
}
|
}
|
||||||
|
|
@ -105,7 +109,6 @@ function searchSongsEnter(e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function searchSongs(searchTerm){
|
async function searchSongs(searchTerm){
|
||||||
let optionslist = []
|
|
||||||
document.getElementById("songlist").innerHTML = ""
|
document.getElementById("songlist").innerHTML = ""
|
||||||
searchResults = await getFromServer({search:searchTerm},"search").then()
|
searchResults = await getFromServer({search:searchTerm},"search").then()
|
||||||
//generate the visual song list
|
//generate the visual song list
|
||||||
|
|
@ -345,7 +348,7 @@ async function submitPerms(e) {
|
||||||
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("volumechangesettingcheckbox").checked;
|
||||||
let returncode = await getFromServer({"setting":"perms","admin":tempData},"settings");
|
let returncode = await getFromServer({"setting":"perms","admin":tempData},"settings");
|
||||||
if (returncode == ERR_NO_ADMIN || returncode == null) {
|
if (returncode == ERR_NO_ADMIN || returncode == null) {
|
||||||
// if you aren't allowed to check the box then toggle it again
|
// if you aren't allowed to check the box then toggle it again
|
||||||
|
|
@ -366,10 +369,13 @@ document.addEventListener('keydown', function(e){
|
||||||
}})
|
}})
|
||||||
document.getElementById("playlist-mode").style.display = "none";
|
document.getElementById("playlist-mode").style.display = "none";
|
||||||
document.getElementById("settings-mode").style.display = "none";
|
document.getElementById("settings-mode").style.display = "none";
|
||||||
//.ontouch for mobile??
|
|
||||||
document.getElementById("volumerange").onchange = async function() {
|
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")
|
let returnValue = await getFromServer({setting:"volume",level:this.value}, "settings")
|
||||||
if (returnValue["volumePassed"] !=0) {
|
if (returnValue == ERR_NO_ADMIN) {
|
||||||
|
alertText("Error: Admin restricted action");
|
||||||
|
} else if (returnValue["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")
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,11 @@ h4 {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.item {
|
||||||
|
/* Only actually applies to playlist and search because settings item has "inherit" bg-colour */
|
||||||
|
background-color: #DDDDDD;
|
||||||
|
}
|
||||||
|
|
||||||
/* Songlist stuff */
|
/* Songlist stuff */
|
||||||
.songlist {
|
.songlist {
|
||||||
width: 80%;
|
width: 80%;
|
||||||
|
|
@ -87,7 +92,6 @@ h4 {
|
||||||
max-width: 150px;
|
max-width: 150px;
|
||||||
margin: 5px auto;
|
margin: 5px auto;
|
||||||
min-width: 75px;
|
min-width: 75px;
|
||||||
background-color: inherit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.songlist > .item > img{
|
.songlist > .item > img{
|
||||||
|
|
@ -160,7 +164,7 @@ h4 {
|
||||||
.settings > .item {
|
.settings > .item {
|
||||||
margin-left: 10%;
|
margin-left: 10%;
|
||||||
width:fit-content;
|
width:fit-content;
|
||||||
|
background-color: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
.settings > .item:not(:last-child) {
|
.settings > .item:not(:last-child) {
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,9 @@ ADMIN_PASS = args.admin
|
||||||
if not(ADMIN_PASS):
|
if not(ADMIN_PASS):
|
||||||
ADMIN_PASS = None
|
ADMIN_PASS = None
|
||||||
# True = everyone, False = admin only. Change in client while in use.
|
# True = everyone, False = admin only. Change in client while in use.
|
||||||
|
"""PP,SK,AS,PM,VOL all set to True or False
|
||||||
|
False is admin only
|
||||||
|
True is all users"""
|
||||||
controlPerms = {
|
controlPerms = {
|
||||||
"PP":True, #done
|
"PP":True, #done
|
||||||
"SK":True, #done
|
"SK":True, #done
|
||||||
|
|
@ -192,12 +195,12 @@ 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']) or controlPerms["AS"]:
|
||||||
# Pass exists and is correct, or it's not restricted
|
# Pass exists and is correct, or it's not restricted
|
||||||
queueSong(recieveData['song'])
|
queueSong(recieveData['song'])
|
||||||
return "200"
|
return "200"
|
||||||
else:
|
else:
|
||||||
# Pass exists, and the action is restricted
|
# the pass is incorrect (technically a pass not existing falls into the above case because controlPerms is never changed)
|
||||||
return ERR_NO_ADMIN
|
return ERR_NO_ADMIN
|
||||||
|
|
||||||
@app.route("/playlist", methods=["POST"])
|
@app.route("/playlist", methods=["POST"])
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,16 @@
|
||||||
* Allows restricting certain features and changing permissions on the fly on the client
|
* Allows restricting certain features and changing permissions on the fly on the client
|
||||||
- [ ] Refactoring existing code
|
- [ ] Refactoring existing code
|
||||||
- [ ] Update the SQL -> Server -> Client pipeline when searching and building playlist
|
- [ ] Update the SQL -> Server -> Client pipeline when searching and building playlist
|
||||||
|
- [ ] Verify all if-else sequences are correct and not redundant
|
||||||
|
- [ ] Remove old comments
|
||||||
- [ ] Secure Password
|
- [ ] Secure Password
|
||||||
* Actually use SSL for stuff that should be using it
|
* Actually use SSL for stuff that should be using it
|
||||||
- [ ] GUI update for client
|
- [ ] GUI update for client
|
||||||
- [ ] Google material design??
|
- [ ] Google material design??
|
||||||
- [ ] Dark mode?
|
- [ ] Dark mode?
|
||||||
- [ ] New Icons
|
- [ ] New Icons
|
||||||
|
- [ ] "Credit" system so each client can only add a set number of songs
|
||||||
|
- Based on time period, number in queue, other possible ideas for credits
|
||||||
|
- Without a login system there's no easy way to give credits to specific clients (and a login is beyond scope of what I want to do)
|
||||||
|
- Potentially a "redemption code" system, which can be tracked client side
|
||||||
|
- All of this is also very hackable without a server-side login.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue