http responses are entirely rewritten #6
2 changed files with 19 additions and 15 deletions
|
|
@ -59,10 +59,8 @@ async function getFromServer(bodyInfo, source="",password=adminPass) {
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log("error print here:");
|
console.log("error print here:");
|
||||||
console.log(e);
|
console.log(e);
|
||||||
if (e == "TypeError: Failed to fetch"){
|
if (e.contains("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 {
|
} else {
|
||||||
alertText("Error: " + e);
|
alertText("Error: " + e);
|
||||||
}
|
}
|
||||||
|
|
@ -133,7 +131,8 @@ function searchSongsEnter(e) {
|
||||||
|
|
||||||
async function searchSongs(searchTerm){
|
async function searchSongs(searchTerm){
|
||||||
document.getElementById("songlist").innerHTML = ""
|
document.getElementById("songlist").innerHTML = ""
|
||||||
searchResults = await getFromServer({search:searchTerm},"search").then()
|
let fetchResults = await getFromServer({search:searchTerm},"search").then();
|
||||||
|
let searchResults = fetchResults.data;
|
||||||
//generate the visual song list
|
//generate the visual song list
|
||||||
for(var fileName in searchResults) {
|
for(var fileName in searchResults) {
|
||||||
let currentSongInJSON = searchResults[fileName]
|
let currentSongInJSON = searchResults[fileName]
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ args = parser.parse_args()
|
||||||
dotenv.load_dotenv()
|
dotenv.load_dotenv()
|
||||||
portTheUserPicked=os.getenv("SERVER_PORT")
|
portTheUserPicked=os.getenv("SERVER_PORT")
|
||||||
|
|
||||||
ERR_NO_ADMIN = ({"error":"no-admin"},401)
|
ERR_NO_ADMIN = ({"error":"no-admin","data":None},401)
|
||||||
ERR_200 = ({"error":"OK"},200)
|
ERR_200 = ({"error":"OK","data":None},200)
|
||||||
if args.admin:
|
if args.admin:
|
||||||
ADMIN_PASS = hashlib.sha256(bytes(args.admin,'utf-8')).hexdigest()
|
ADMIN_PASS = hashlib.sha256(bytes(args.admin,'utf-8')).hexdigest()
|
||||||
else:
|
else:
|
||||||
|
|
@ -130,9 +130,9 @@ def playerControls():
|
||||||
else:
|
else:
|
||||||
return ERR_NO_ADMIN
|
return ERR_NO_ADMIN
|
||||||
else:
|
else:
|
||||||
return {"error":"Not a valid control"},400
|
return {"error":"Not a valid control","data":None},400
|
||||||
else:
|
else:
|
||||||
return {"error":"No control sent"},400
|
return {"error":"No control sent","data":None},400
|
||||||
|
|
||||||
@app.route("/settings", methods=['POST'])
|
@app.route("/settings", methods=['POST'])
|
||||||
def settingsControl():
|
def settingsControl():
|
||||||
|
|
@ -143,8 +143,11 @@ 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):
|
||||||
volumePassed = player.audio_set_volume(int(recieveData["level"]))
|
volumePassed = player.audio_set_volume(int(recieveData["level"]))
|
||||||
return {"volumePassed":volumePassed}
|
return {"error":"ok","data":{"volumePassed":volumePassed}},200
|
||||||
|
else:
|
||||||
|
return {"error":"Invalid volume level","data":None}
|
||||||
else:
|
else:
|
||||||
return ERR_NO_ADMIN
|
return ERR_NO_ADMIN
|
||||||
elif recieveData["setting"] == "partymode-toggle":
|
elif recieveData["setting"] == "partymode-toggle":
|
||||||
|
|
@ -161,9 +164,9 @@ def settingsControl():
|
||||||
return ERR_NO_ADMIN
|
return ERR_NO_ADMIN
|
||||||
elif recieveData["setting"] == "getsettings":
|
elif recieveData["setting"] == "getsettings":
|
||||||
# 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 {"partymode":partyMode,"volume":player.audio_get_volume(),"admin":controlPerms}
|
return {"error":"ok","data":{"partymode":partyMode,"volume":player.audio_get_volume(),"admin":controlPerms}},200
|
||||||
else:
|
else:
|
||||||
return "400"
|
return {"error":"Not a valid setting","data":None},400
|
||||||
|
|
||||||
@app.route("/search", methods=['POST'])
|
@app.route("/search", methods=['POST'])
|
||||||
def searchSongDB():
|
def searchSongDB():
|
||||||
|
|
@ -188,12 +191,13 @@ def searchSongDB():
|
||||||
"lossless":i[5]
|
"lossless":i[5]
|
||||||
}
|
}
|
||||||
fileofDB.close()
|
fileofDB.close()
|
||||||
return tempdata
|
|
||||||
|
return {"error":"ok","data":tempdata},200
|
||||||
|
|
||||||
@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']) or controlPerms["AS"]:
|
if (ADMIN_PASS == recieveData['password']) or controlPerms["AS"]:
|
||||||
# Password exists and is correct, or it's not restricted
|
# Password exists and is correct, or it's not restricted
|
||||||
# if (recieveData['song'] in playlist):
|
# if (recieveData['song'] in playlist):
|
||||||
# return {"error":"song-in-queue"}
|
# return {"error":"song-in-queue"}
|
||||||
|
|
@ -239,7 +243,8 @@ def getPlaylist():
|
||||||
}
|
}
|
||||||
tempPlaylist.append({i:k})
|
tempPlaylist.append({i:k})
|
||||||
fileofDB.close()
|
fileofDB.close()
|
||||||
return tempPlaylist
|
|
||||||
|
return {"error":"ok","data":tempPlaylist}
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# There's not really a whole lot of point to a main function for something like this, you'd never use any of these methods
|
# There's not really a whole lot of point to a main function for something like this, you'd never use any of these methods
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue