diff --git a/.gitignore b/.gitignore index a2d6b61..87c9ad3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -Server/sound/ +server/sound/ *.db start.bat .env diff --git a/Client/ext/popper.js b/Client/ext/popper.js new file mode 100644 index 0000000..19a42b9 --- /dev/null +++ b/Client/ext/popper.js @@ -0,0 +1,134 @@ +function Pop() { + // var cssRuleFile = "/src/css/style.css"; // will be the link once this css file became available online + var cssRuleFile = "https://cookieconsent.popupsmart.com/src/css/style.css"; // will be the link once this css file became available online + + let lnk = document.createElement("link"); + lnk.setAttribute("rel", "stylesheet"); + lnk.setAttribute("type", "text/css"); + lnk.setAttribute("href", cssRuleFile); + document.getElementsByTagName("head")[0].appendChild(lnk); + + let styl = "undefined"; + var conDivObj; + + var fadeInTime = 10; // If needed could be served as an customizable option to the user + var fadeOutTime = 10; + + let cookie = { + name: "cookieconsent_status", + path: "/", + expiryDays: 365 * 24 * 60 * 60 * 5000, + }; + + let content = { + /// Add a field for link color + message: + "This website uses cookies to ensure you get the best experience on our website.", + btnText: "Got it!", + mode: " banner bottom", + theme: " theme-classic", + palette: " palette1", + link: "Learn more", + href: "https://www.cookiesandyou.com", + target: "_blank", + }; + + let createPopUp = function () { + console.log(content); + if (typeof conDivObj === "undefined") { + conDivObj = document.createElement("DIV"); + conDivObj.style.opacity = 0; + conDivObj.setAttribute("id", "spopupCont"); + } + conDivObj.innerHTML = + '
' + + content.message + + '" + + content.link + + '
' + + content.btnText + + '
Powered by Popupsmart
'; + + document.body.appendChild(conDivObj); + fadeIn(conDivObj); + + document + .getElementById("cookie-btn") + .addEventListener("click", function () { + saveCookie(); + fadeOut(conDivObj); + }); + }; + + let fadeOut = function (element) { + var op = 1; + var timer = setInterval(function () { + if (op <= 0.1) { + clearInterval(timer); + conDivObj.parentElement.removeChild(conDivObj); + } + element.style.opacity = op; + element.style.filter = "alpha(opacity=" + op * 100 + ")"; + op -= op * 0.1; + }, fadeOutTime); + }; + let fadeIn = function (element) { + var op = 0.1; + var timer = setInterval(function () { + if (op >= 1) { + clearInterval(timer); + } + element.style.opacity = op; + element.style.filter = "alpha(opacity=" + op * 100 + ")"; + op += op * 0.1; + }, fadeInTime); + }; + + let checkCookie = function (key) { + var keyValue = document.cookie.match("(^|;) ?" + key + "=([^;]*)(;|$)"); + return keyValue ? true : false; + }; + + let saveCookie = function () { + var expires = new Date(); + expires.setTime(expires.getTime() + cookie.expiryDays); + document.cookie = + cookie.name + + "=" + + "ok" + + ";expires=" + + expires.toUTCString() + + "path=" + + cookie.path; + }; + + this.init = function (param) { + if (checkCookie(cookie.name)) return; + + if (typeof param === "object") { + if ("ButtonText" in param) content.btnText = param.ButtonText; + if ("Mode" in param) content.mode = " " + param.Mode; + if ("Theme" in param) content.theme = " " + param.Theme; + if ("Palette" in param) content.palette = " " + param.Palette; + if ("Message" in param) content.message = param.Message; + if ("LinkText" in param) content.link = param.LinkText; + if ("Location" in param) content.href = param.Location; + if ("Target" in param) content.target = param.Target; + if ("Time" in param) + setTimeout(function () { + createPopUp(); + }, param.Time * 1000); + else createPopUp(); + } + }; +} +window.start = new Pop(); diff --git a/Server/static/ext/qrcode.min.js b/Client/ext/qrcode.min.js similarity index 100% rename from Server/static/ext/qrcode.min.js rename to Client/ext/qrcode.min.js diff --git a/Server/static/favicon.ico b/Client/favicon.ico similarity index 100% rename from Server/static/favicon.ico rename to Client/favicon.ico diff --git a/Server/static/images/Icon-144.png b/Client/images/Icon-144.png similarity index 100% rename from Server/static/images/Icon-144.png rename to Client/images/Icon-144.png diff --git a/Server/static/images/Screenshot-Main-Desktop.png b/Client/images/Screenshot-Main-Desktop.png similarity index 100% rename from Server/static/images/Screenshot-Main-Desktop.png rename to Client/images/Screenshot-Main-Desktop.png diff --git a/Server/static/images/Screenshot-Main-Mobile.png b/Client/images/Screenshot-Main-Mobile.png similarity index 100% rename from Server/static/images/Screenshot-Main-Mobile.png rename to Client/images/Screenshot-Main-Mobile.png diff --git a/Server/static/images/placeholder.png b/Client/images/placeholder.png similarity index 100% rename from Server/static/images/placeholder.png rename to Client/images/placeholder.png diff --git a/Server/static/images/play-pause-old.png b/Client/images/play-pause-old.png similarity index 100% rename from Server/static/images/play-pause-old.png rename to Client/images/play-pause-old.png diff --git a/Server/static/images/play-pause.png b/Client/images/play-pause.png similarity index 100% rename from Server/static/images/play-pause.png rename to Client/images/play-pause.png diff --git a/Server/static/images/playlist.png b/Client/images/playlist.png similarity index 100% rename from Server/static/images/playlist.png rename to Client/images/playlist.png diff --git a/Server/static/images/search.png b/Client/images/search.png similarity index 100% rename from Server/static/images/search.png rename to Client/images/search.png diff --git a/Server/static/images/settings.png b/Client/images/settings.png similarity index 100% rename from Server/static/images/settings.png rename to Client/images/settings.png diff --git a/Server/static/images/skip.png b/Client/images/skip.png similarity index 100% rename from Server/static/images/skip.png rename to Client/images/skip.png diff --git a/Server/templates/index.html b/Client/index.html similarity index 80% rename from Server/templates/index.html rename to Client/index.html index 1cbc5cf..3a86b52 100644 --- a/Server/templates/index.html +++ b/Client/index.html @@ -3,15 +3,17 @@ Jukebox Controller - - - + + - + - + + + +

Jukebox Remote

Add songs to the shared playlist below!

@@ -61,11 +63,11 @@ changes visibility with JS-->

Opposite of light mode

- +

Alert Time:

How long alerts stay on screen for (seconds)

@@ -112,21 +114,20 @@ changes visibility with JS-->

Wipe the playlist, except the currently playing song. With PartyMode enabled, a second song will be added back randomly

-

PartyJukebox is under an AGPLV3 liscense. You can access the source code here.

-

Release {{ REL_VER_NUM }}

+

PartyJukebox is under an AGPLV3 liscense. You can access the source code here.

- Playlist - Play pause - Skip - Search + Playlist + Play pause + Skip + Search
- settings + settings
- - + + \ No newline at end of file diff --git a/Server/static/manifest.json b/Client/manifest.json similarity index 96% rename from Server/static/manifest.json rename to Client/manifest.json index 9ab490f..975ff13 100644 --- a/Server/static/manifest.json +++ b/Client/manifest.json @@ -2,7 +2,7 @@ "name": "Jukebox Remote", "short_name": "Jukebox Remote", "description": "Controller for the PartyJukebox server app.", - "start_url": "/", + "start_url": "index.html", "display": "standalone", "background_color": "#eeeeee", "theme_color": "#eeeeee", diff --git a/Server/static/scripts.js b/Client/scripts.js similarity index 87% rename from Server/static/scripts.js rename to Client/scripts.js index 1cd85e7..58e923b 100644 --- a/Server/static/scripts.js +++ b/Client/scripts.js @@ -1,5 +1,5 @@ // set all the global stuff -let ip = URL.parse(document.URL).host; +let ip; let alertTime = 2; let adminPass = ""; let justSkipped = false; @@ -15,7 +15,7 @@ let currentlyPlaying = false; const params = new URLSearchParams(location.search); let darkmodetemp = getCookie("darkmode"); -if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches && darkmodetemp === undefined) { +if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { darkmodetemp = "true"; } if(darkmodetemp === "") { @@ -40,42 +40,14 @@ async function alertText(text="Song Added!") { alertbox.innerHTML = "" } } - -async function getFromServer(source,headersIn={},secure = false, password=adminPass) { - try { - let href = ""; - if(secure) { - href = "https://"+ip+"/" + source; - } else { - href = "http://"+ip+"/" + source; - } - headersIn["Jukebox-Auth"] = password; - headersIn["Accept"] = "application/json"; - let response = await fetch(href,{ - method:"GET", - headers:headersIn, - }) - let data = await response.json(); - if (response.status == ERR_NO_ADMIN) { - alertText("Error: Admin restricted action") - } else if(!response.ok){ - throw new Error(data.error); - } - // we add some information from the response just in case it is needed - data["ok"] = response.ok; - data["status"] = response.status; - // console.log(data); - return await data; - } catch(e) { - alertText(e); - } - -} - // a lot of this is kinda waffly because i was trying to get // it to return the right stuff and javascript is asyrcronouse (boo) -async function postFromServer(bodyInfo, source="", secure=false, password=adminPass) { +async function getFromServer(bodyInfo, source="", secure=false, password=adminPass) { try{ + if (bodyInfo != null) { + // the currently set password is always included in every request + bodyInfo["password"] = password; + } let href = ""; if(secure) { href = "https://"+ip+"/" + source; @@ -86,8 +58,7 @@ async function postFromServer(bodyInfo, source="", secure=false, password=adminP method: "POST", body: JSON.stringify(bodyInfo), headers: { - "Content-type": "application/json; charset=UTF-8", - "Jukebox-Auth": password + "Content-type": "application/json; charset=UTF-8" } }); @@ -110,7 +81,7 @@ async function postFromServer(bodyInfo, source="", secure=false, password=adminP // console.log("error print here:"); // console.log(e); if (e.toString().includes("TypeError: Failed to fetch")){ - alertText("Error: Can't Connect to Server") + alertText("Error: Can't Connect to Server (is the ip set?)") } else { alertText(e); } @@ -140,12 +111,12 @@ function getCookie(cname) { // also someone who likes things not being dumb more than me would have separated the client and server buttons async function controlButton(buttonType) { if (buttonType == "pp") { // Play-Pause button - let result = await postFromServer({control: "play-pause"}, "controls"); + let result = await getFromServer({control: "play-pause"}, "controls"); // console.log(result); currentlyPlaying = result["data"]["playingState"]; } else if (buttonType == "sk") { // Skip button // clearInterval(playlistTimeTimer); - let returnCode = await postFromServer({control: "skip"}, "controls"); + let returnCode = await getFromServer({control: "skip"}, "controls"); // console.log(returnCode["ok"]) if(returnCode["ok"]) { if (document.getElementById("playlist-mode").style.display == "block") { @@ -178,7 +149,7 @@ async function controlButton(buttonType) { document.getElementById("settings-mode").style.display = "block"; checkSettings() } else if (buttonType == "pm") { //Partymode toggle (in settings) - let response = await postFromServer({setting: "partymode-toggle"}, "settings") + let response = await getFromServer({setting: "partymode-toggle"}, "settings") if(response.ok) { justChangedSetting = true; checkSettings(); @@ -198,17 +169,11 @@ function searchSongsEnter(e) { } } -async function searchSongs(searchTerm,page=-1){ +async function searchSongs(searchTerm){ document.getElementById("songlist").innerHTML = "" - let fetchResults = await getFromServer("search?query="+searchTerm+"&page="+page); - let searchResults = fetchResults.data.songsobj; + let fetchResults = await getFromServer({search:searchTerm},"search").then(); + let searchResults = fetchResults.data; //generate the visual song list - // let x = document.createElement("button") - // x.addEventListener("click",()=>{ - // searchSongs(searchTerm,page+1); - // }) - // x.textContent = "Next Page" - // document.getElementById("songlist-mode").appendChild(x) for(var fileName in searchResults) { let currentSongInJSON = searchResults[fileName] let newItem = document.createElement("div"); @@ -222,14 +187,12 @@ async function searchSongs(searchTerm,page=-1){ } image.src = currentSongInJSON["art"]; } catch(err){ - image.src = "/static/images/placeholder.png"; + image.src = "./images/placeholder.png"; } image.id = String(fileName)+" image"; let head3 = document.createElement("h3"); - head3.id = fileName; head3.innerText = currentSongInJSON["title"]; let head4 = document.createElement("h4"); - head4.id = fileName; head4.innerText = currentSongInJSON["artist"]; newItem.appendChild(image); newItem.appendChild(head3); @@ -247,8 +210,6 @@ async function searchSongs(searchTerm,page=-1){ if (JSON.stringify(searchResults)==JSON.stringify({})) { //display error if no results document.getElementById("songlist").innerHTML = "

We might not have that one...

"; - } else { - } } @@ -265,8 +226,40 @@ function alertTimeSet(time) { alertText("Alerts stay on screen for " + alertTime.toString() + " seconds") } +function ipSetEnter(e){ + if (e.key == "Enter") { + e.preventDefault(); + // why on gosh's green earth am i sending a value here? + // im gonna get rid of all these individual "enter" dectectors and do something + // like i did for the keyboard selection of elements + // basically just if(e==click || e.key == enter) + ipSetter(document.getElementById("iptextbox").value) + } +} + +function ipSetter(){ + ipBox = document.getElementById("iptextbox").value + if (ipBox == "") { + alertText("Your IP is set to "+ip) + } else { + if (ipBox.includes(":")) { + port = ipBox.slice(ipBox.indexOf(":")+1) + ip = ipBox; + document.cookie = "ip="+ip+"; path=/;" + alertText("Your IP is now set to "+ip.slice(0, ipBox.indexOf(":"))+" at port "+port) + } else { + ip = ipBox + ":19054" + document.cookie = "ip="+ip+"; path=/;" + alertText("Your IP is now set to "+ipBox+" at port 19054 (Default)") + } + } + // anytime the server ip changes the qrcode should change to use it + qrCodeGenerate() + +} + function qrCodeGenerate() { - let tempURL = "http://" + URL.parse(document.location.href).host + let tempURL = "http://" + document.location.href.split("/")[2] + "/?ip=" + ip; document.getElementById("qrcode").innerHTML = ""; // get the current foreground and background let dark = window.getComputedStyle(document.body).getPropertyValue("--text-color"); @@ -324,12 +317,12 @@ async function updateSingleSetting(data) { async function checkSettings(skipServer=false) { //check client stuff first so if the server doesn't exist it can still be changed and seen - // if (ip.slice(-5)=="19054") { - // // don't show the port if it is the default - // document.getElementById("iptextbox").value = ip.slice(0,-6) - // } else { - // document.getElementById("iptextbox").value = ip; - // } + if (ip.slice(-5)=="19054") { + // don't show the port if it is the default + document.getElementById("iptextbox").value = ip.slice(0,-6) + } else { + document.getElementById("iptextbox").value = ip; + } qrCodeGenerate() document.getElementById("alerttimetextbox").value = alertTime partyButtonState = document.getElementById("partymode-button").innerHTML; @@ -341,7 +334,7 @@ async function checkSettings(skipServer=false) { } } //ping the server here - data = await getFromServer("settings"); + data = await getFromServer({setting: "getsettings"}, "settings"); x = data["data"]; if (!(skipServer) || partyButtonState=="N/A") { if (x["partymode"] == false) { @@ -379,7 +372,7 @@ async function addToPlaylist(songObject) { } image.src = songObject[newItem.id]["art"]; } catch(err){ - image.src = "static/images/placeholder.png"; + image.src = "./images/placeholder.png"; } image.id = String(songObject[newItem.id])+" image"; let head3 = document.createElement("h3"); @@ -438,7 +431,7 @@ async function skipInPlaylist() { async function generateVisualPlaylist(conditions="") { document.getElementById("playlist").innerHTML = "

"; - data = await getFromServer("playlist"); + data = await getFromServer(null, "playlist"); playlist = data["data"]["playlist"]; currentlyPlaying = data["data"]["playingState"] playlist = Object.values(playlist).map(obj => { @@ -469,7 +462,7 @@ async function generateVisualPlaylist(conditions="") { } image.src = playlist[i]["art"]; } catch(err){ - image.src = "/static/images/placeholder.png"; + image.src = "./images/placeholder.png"; } image.id = String(fileName)+" image"; let head3 = document.createElement("h3"); @@ -516,9 +509,9 @@ async function generateVisualPlaylist(conditions="") { } async function submitSong(songid) { - let returncode = await postFromServer({song: songid}, "songadd"); + let returncode = await getFromServer({song: songid}, "songadd"); if(returncode["status"] === ERR_NO_ADMIN) { - // right now the error is alerted in postFromServer, maybe will change that + // right now the error is alerted in getFromServer, maybe will change that } else if(returncode["status"]!==200) { alertText("That song's already in the queue! Hang on!") } else { @@ -528,7 +521,6 @@ async function submitSong(songid) { function checkWhatSongWasClicked(e) { if(e.type == "click" || e.key == "Enter") { itemId = e.srcElement.id; - // console.log(e.srcElement); if ((itemId.length-itemId.lastIndexOf("image") == 5) && itemId.lastIndexOf("image")!=-1) { itemId = itemId.slice(0,-6) } @@ -592,7 +584,7 @@ async function submitPerms(e) { tempData["PM"] = document.getElementById("partymodesettingcheckbox").checked; tempData["VOL"] = document.getElementById("volumechangesettingcheckbox").checked; tempData["DUP"] = document.getElementById("duplicateallowesettingcheckbox").checked; - let returncode = await postFromServer({"setting":"perms","admin":tempData},"settings"); + let returncode = await getFromServer({"setting":"perms","admin":tempData},"settings"); if (!(returncode["ok"])) { // 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 @@ -604,8 +596,8 @@ async function submitPerms(e) { } async function clearPlaylist() { - let returncode = await postFromServer({control:"clear"},"controls"); - if(returncode["status"] === ERR_NO_ADMIN || returncode == null) { + let returncode = await getFromServer({control:"clear"},"controls"); + if(returncode == ERR_NO_ADMIN || returncode == null) { // alertText("Admin Restricted ") // there's an admin restrict alert built into getFromServer } else { @@ -626,8 +618,8 @@ document.getElementById("playlist-mode").style.display = "none"; document.getElementById("settings-mode").style.display = "none"; document.getElementById("volumerange").onchange = async function(e) { // there is no reason for this not to be a defined function - // TODO: FIX THIS - let returnValue = await postFromServer({setting:"volume",level:e.target.value}, "settings") + // FIX THIS + let returnValue = await getFromServer({setting:"volume",level:e.target.value}, "settings") if (returnValue["status"] == ERR_NO_ADMIN) { // alertText("Error: Admin restricted action"); // there's an admin restrict alert built into getFromServer @@ -656,7 +648,7 @@ document.getElementById("search-button").addEventListener('click', function(){co document.getElementById("skip-button").addEventListener('click',function(){controlButton("sk")}); document.getElementById("go-search").addEventListener('click', function(){searchSongs(document.getElementById("songsearch").value)}) document.getElementById("songsearch").addEventListener('keydown', function(e){searchSongsEnter(e)}); -// document.getElementById("iptextbox").addEventListener('keydown', function(e){ipSetEnter(e)}); +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(e){submitPerms(e)}); @@ -672,6 +664,20 @@ document.getElementById("songlist").addEventListener('click', function(e){checkW // let tempWidth = document.getElementById('controls').clientWidth; // document.getElementById("controls").style.marginLeft = "-"+String(parseInt(tempWidth/2))+"px"; +//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 +//example (http://192.168.1.100:8000/?ip=192.168.1.100:19054 sets the ip to the same host at the default port) +//the port must be set manually using this method, but only has to be done once for the url that ends up being shared + +//tries the url first, then the cookie, then the default +ip = params.get("ip") +if (ip == null || ip=="") { + ip=getCookie("ip") +} +if (ip==null || ip==""){ + ip = "" +} + // saving the cookies (don't tell the EU) document.cookie = "ip="+ip+"; path=/;" @@ -701,8 +707,7 @@ socket.on("timeUpdate", function(data) { // console.log("recieved data from timeUpdate"); // console.log(data); playlistElapsedSeconds = data["elapsedTime"]; - currentlyPlaying = data["playingState"]; - playlistSongLength = data["songLength"] + currentlyPlaying = data["playingState"] }); socket.on("skipSong",() => { diff --git a/Server/static/styles.css b/Client/styles.css similarity index 99% rename from Server/static/styles.css rename to Client/styles.css index f2e3e27..70bd991 100644 --- a/Server/static/styles.css +++ b/Client/styles.css @@ -235,6 +235,7 @@ h4 { .versionNumber { font-size: 11px; + font-style: italic; text-align: left; width: 80%; } diff --git a/Server/__pycache__/versionNum.cpython-313.pyc b/Server/__pycache__/versionNum.cpython-313.pyc deleted file mode 100644 index d9f0a4b..0000000 Binary files a/Server/__pycache__/versionNum.cpython-313.pyc and /dev/null differ diff --git a/Server/databaseGenerator.py b/Server/databaseGenerator.py index 6a4f09a..ebf8263 100644 --- a/Server/databaseGenerator.py +++ b/Server/databaseGenerator.py @@ -11,18 +11,18 @@ parser=argparse.ArgumentParser(description="Options for the generation of the so # parser.add_argument('-k','--apikey', help='String: LastFM api key', default="") parser.add_argument('-m', '--mode', help='new/update: Remake database or update current', default= "update") parser.add_argument('-a', '--art', help="True/False: Add art to the database using LastFm (takes minimum 0.25s per song)", default="True") -# parser.add_argument('-d','--directory',help="Directory of the song files", default="./sound/") +parser.add_argument('-d','--directory',help="Directory of the song files", default="./sound/") args = parser.parse_args() dotenv.load_dotenv() apikeylastfm = os.getenv("API_KEY") soundLocation = os.getenv("DIRECTORY") # apikeylastfm = args.apikey -if soundLocation[-1] == "/" or soundLocation[-1] == "\\": - soundLocation = soundLocation -elif "/" in soundLocation: - soundLocation = soundLocation + "/" +if args.directory[-1] == "/" or args.directory[-1] == "\\": + soundLocation = args.directory +elif "/" in args.directory: + soundLocation = args.directory + "/" else: - soundLocation = soundLocation + "\\" + soundLocation = args.directory + "\\" songFiles = os.listdir(soundLocation) fileOfDB = sql.connect("songDatabase.db") diff --git a/Server/static/ext/sha256.min.js b/Server/static/ext/sha256.min.js deleted file mode 100644 index 7fe9102..0000000 --- a/Server/static/ext/sha256.min.js +++ /dev/null @@ -1,9 +0,0 @@ -/** - * [js-sha256]{@link https://github.com/emn178/js-sha256} - * - * @version 0.11.0 - * @author Chen, Yi-Cyuan [emn178@gmail.com] - * @copyright Chen, Yi-Cyuan 2014-2024 - * @license MIT - */ -!function(){"use strict";function t(t,i){i?(d[0]=d[16]=d[1]=d[2]=d[3]=d[4]=d[5]=d[6]=d[7]=d[8]=d[9]=d[10]=d[11]=d[12]=d[13]=d[14]=d[15]=0,this.blocks=d):this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t?(this.h0=3238371032,this.h1=914150663,this.h2=812702999,this.h3=4144912697,this.h4=4290775857,this.h5=1750603025,this.h6=1694076839,this.h7=3204075428):(this.h0=1779033703,this.h1=3144134277,this.h2=1013904242,this.h3=2773480762,this.h4=1359893119,this.h5=2600822924,this.h6=528734635,this.h7=1541459225),this.block=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0,this.is224=t}function i(i,r,s){var e,n=typeof i;if("string"===n){var o,a=[],u=i.length,c=0;for(e=0;e>>6,a[c++]=128|63&o):o<55296||o>=57344?(a[c++]=224|o>>>12,a[c++]=128|o>>>6&63,a[c++]=128|63&o):(o=65536+((1023&o)<<10|1023&i.charCodeAt(++e)),a[c++]=240|o>>>18,a[c++]=128|o>>>12&63,a[c++]=128|o>>>6&63,a[c++]=128|63&o);i=a}else{if("object"!==n)throw new Error(h);if(null===i)throw new Error(h);if(f&&i.constructor===ArrayBuffer)i=new Uint8Array(i);else if(!(Array.isArray(i)||f&&ArrayBuffer.isView(i)))throw new Error(h)}i.length>64&&(i=new t(r,!0).update(i).array());var y=[],p=[];for(e=0;e<64;++e){var l=i[e]||0;y[e]=92^l,p[e]=54^l}t.call(this,r,s),this.update(p),this.oKeyPad=y,this.inner=!0,this.sharedMemory=s}var h="input is invalid type",r="object"==typeof window,s=r?window:{};s.JS_SHA256_NO_WINDOW&&(r=!1);var e=!r&&"object"==typeof self,n=!s.JS_SHA256_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;n?s=global:e&&(s=self);var o=!s.JS_SHA256_NO_COMMON_JS&&"object"==typeof module&&module.exports,a="function"==typeof define&&define.amd,f=!s.JS_SHA256_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,u="0123456789abcdef".split(""),c=[-2147483648,8388608,32768,128],y=[24,16,8,0],p=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],l=["hex","array","digest","arrayBuffer"],d=[];!s.JS_SHA256_NO_NODE_JS&&Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),!f||!s.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView||(ArrayBuffer.isView=function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer});var A=function(i,h){return function(r){return new t(h,!0).update(r)[i]()}},w=function(i){var h=A("hex",i);n&&(h=b(h,i)),h.create=function(){return new t(i)},h.update=function(t){return h.create().update(t)};for(var r=0;r>>2]|=t[n]<>>2]|=s<>>2]|=(192|s>>>6)<>>2]|=(128|63&s)<=57344?(a[e>>>2]|=(224|s>>>12)<>>2]|=(128|s>>>6&63)<>>2]|=(128|63&s)<>>2]|=(240|s>>>18)<>>2]|=(128|s>>>12&63)<>>2]|=(128|s>>>6&63)<>>2]|=(128|63&s)<=64?(this.block=a[16],this.start=e-64,this.hash(),this.hashed=!0):this.start=e}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296<<0,this.bytes=this.bytes%4294967296),this}},t.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,i=this.lastByteIndex;t[16]=this.block,t[i>>>2]|=c[3&i],this.block=t[16],i>=56&&(this.hashed||this.hash(),t[0]=this.block,t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[14]=this.hBytes<<3|this.bytes>>>29,t[15]=this.bytes<<3,this.hash()}},t.prototype.hash=function(){var t,i,h,r,s,e,n,o,a,f=this.h0,u=this.h1,c=this.h2,y=this.h3,l=this.h4,d=this.h5,A=this.h6,w=this.h7,b=this.blocks;for(t=16;t<64;++t)i=((s=b[t-15])>>>7|s<<25)^(s>>>18|s<<14)^s>>>3,h=((s=b[t-2])>>>17|s<<15)^(s>>>19|s<<13)^s>>>10,b[t]=b[t-16]+i+b[t-7]+h<<0;for(a=u&c,t=0;t<64;t+=4)this.first?(this.is224?(e=300032,w=(s=b[0]-1413257819)-150054599<<0,y=s+24177077<<0):(e=704751109,w=(s=b[0]-210244248)-1521486534<<0,y=s+143694565<<0),this.first=!1):(i=(f>>>2|f<<30)^(f>>>13|f<<19)^(f>>>22|f<<10),r=(e=f&u)^f&c^a,w=y+(s=w+(h=(l>>>6|l<<26)^(l>>>11|l<<21)^(l>>>25|l<<7))+(l&d^~l&A)+p[t]+b[t])<<0,y=s+(i+r)<<0),i=(y>>>2|y<<30)^(y>>>13|y<<19)^(y>>>22|y<<10),r=(n=y&f)^y&u^e,A=c+(s=A+(h=(w>>>6|w<<26)^(w>>>11|w<<21)^(w>>>25|w<<7))+(w&l^~w&d)+p[t+1]+b[t+1])<<0,i=((c=s+(i+r)<<0)>>>2|c<<30)^(c>>>13|c<<19)^(c>>>22|c<<10),r=(o=c&y)^c&f^n,d=u+(s=d+(h=(A>>>6|A<<26)^(A>>>11|A<<21)^(A>>>25|A<<7))+(A&w^~A&l)+p[t+2]+b[t+2])<<0,i=((u=s+(i+r)<<0)>>>2|u<<30)^(u>>>13|u<<19)^(u>>>22|u<<10),r=(a=u&c)^u&y^o,l=f+(s=l+(h=(d>>>6|d<<26)^(d>>>11|d<<21)^(d>>>25|d<<7))+(d&A^~d&w)+p[t+3]+b[t+3])<<0,f=s+(i+r)<<0,this.chromeBugWorkAround=!0;this.h0=this.h0+f<<0,this.h1=this.h1+u<<0,this.h2=this.h2+c<<0,this.h3=this.h3+y<<0,this.h4=this.h4+l<<0,this.h5=this.h5+d<<0,this.h6=this.h6+A<<0,this.h7=this.h7+w<<0},t.prototype.hex=function(){this.finalize();var t=this.h0,i=this.h1,h=this.h2,r=this.h3,s=this.h4,e=this.h5,n=this.h6,o=this.h7,a=u[t>>>28&15]+u[t>>>24&15]+u[t>>>20&15]+u[t>>>16&15]+u[t>>>12&15]+u[t>>>8&15]+u[t>>>4&15]+u[15&t]+u[i>>>28&15]+u[i>>>24&15]+u[i>>>20&15]+u[i>>>16&15]+u[i>>>12&15]+u[i>>>8&15]+u[i>>>4&15]+u[15&i]+u[h>>>28&15]+u[h>>>24&15]+u[h>>>20&15]+u[h>>>16&15]+u[h>>>12&15]+u[h>>>8&15]+u[h>>>4&15]+u[15&h]+u[r>>>28&15]+u[r>>>24&15]+u[r>>>20&15]+u[r>>>16&15]+u[r>>>12&15]+u[r>>>8&15]+u[r>>>4&15]+u[15&r]+u[s>>>28&15]+u[s>>>24&15]+u[s>>>20&15]+u[s>>>16&15]+u[s>>>12&15]+u[s>>>8&15]+u[s>>>4&15]+u[15&s]+u[e>>>28&15]+u[e>>>24&15]+u[e>>>20&15]+u[e>>>16&15]+u[e>>>12&15]+u[e>>>8&15]+u[e>>>4&15]+u[15&e]+u[n>>>28&15]+u[n>>>24&15]+u[n>>>20&15]+u[n>>>16&15]+u[n>>>12&15]+u[n>>>8&15]+u[n>>>4&15]+u[15&n];return this.is224||(a+=u[o>>>28&15]+u[o>>>24&15]+u[o>>>20&15]+u[o>>>16&15]+u[o>>>12&15]+u[o>>>8&15]+u[o>>>4&15]+u[15&o]),a},t.prototype.toString=t.prototype.hex,t.prototype.digest=function(){this.finalize();var t=this.h0,i=this.h1,h=this.h2,r=this.h3,s=this.h4,e=this.h5,n=this.h6,o=this.h7,a=[t>>>24&255,t>>>16&255,t>>>8&255,255&t,i>>>24&255,i>>>16&255,i>>>8&255,255&i,h>>>24&255,h>>>16&255,h>>>8&255,255&h,r>>>24&255,r>>>16&255,r>>>8&255,255&r,s>>>24&255,s>>>16&255,s>>>8&255,255&s,e>>>24&255,e>>>16&255,e>>>8&255,255&e,n>>>24&255,n>>>16&255,n>>>8&255,255&n];return this.is224||a.push(o>>>24&255,o>>>16&255,o>>>8&255,255&o),a},t.prototype.array=t.prototype.digest,t.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(this.is224?28:32),i=new DataView(t);return i.setUint32(0,this.h0),i.setUint32(4,this.h1),i.setUint32(8,this.h2),i.setUint32(12,this.h3),i.setUint32(16,this.h4),i.setUint32(20,this.h5),i.setUint32(24,this.h6),this.is224||i.setUint32(28,this.h7),t},(i.prototype=new t).finalize=function(){if(t.prototype.finalize.call(this),this.inner){this.inner=!1;var i=this.array();t.call(this,this.is224,this.sharedMemory),this.update(this.oKeyPad),this.update(i),t.prototype.finalize.call(this)}};var B=w();B.sha256=B,B.sha224=w(!0),B.sha256.hmac=v(),B.sha224.hmac=v(!0),o?module.exports=B:(s.sha256=B.sha256,s.sha224=B.sha224,a&&define(function(){return B}))}(); \ No newline at end of file diff --git a/Server/static/ext/socket.io.min.js b/Server/static/ext/socket.io.min.js deleted file mode 100644 index d6b2d60..0000000 --- a/Server/static/ext/socket.io.min.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! - * Socket.IO v4.7.5 - * (c) 2014-2024 Guillermo Rauch - * Released under the MIT License. - */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).io=t()}(this,(function(){"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,s=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){a=!0,o=e},f:function(){try{s||null==n.return||n.return()}finally{if(a)throw o}}}}var v=Object.create(null);v.open="0",v.close="1",v.ping="2",v.pong="3",v.message="4",v.upgrade="5",v.noop="6";var g=Object.create(null);Object.keys(v).forEach((function(e){g[v[e]]=e}));var m,b={type:"error",data:"parser error"},k="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),w="function"==typeof ArrayBuffer,_=function(e){return"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer},E=function(e,t,n){var r=e.type,i=e.data;return k&&i instanceof Blob?t?n(i):A(i,n):w&&(i instanceof ArrayBuffer||_(i))?t?n(i):A(new Blob([i]),n):n(v[r]+(i||""))},A=function(e,t){var n=new FileReader;return n.onload=function(){var e=n.result.split(",")[1];t("b"+(e||""))},n.readAsDataURL(e)};function O(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}for(var T="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",R="undefined"==typeof Uint8Array?[]:new Uint8Array(256),C=0;C<64;C++)R[T.charCodeAt(C)]=C;var B,S="function"==typeof ArrayBuffer,N=function(e,t){if("string"!=typeof e)return{type:"message",data:x(e,t)};var n=e.charAt(0);return"b"===n?{type:"message",data:L(e.substring(1),t)}:g[n]?e.length>1?{type:g[n],data:e.substring(1)}:{type:g[n]}:b},L=function(e,t){if(S){var n=function(e){var t,n,r,i,o,s=.75*e.length,a=e.length,c=0;"="===e[e.length-1]&&(s--,"="===e[e.length-2]&&s--);var u=new ArrayBuffer(s),h=new Uint8Array(u);for(t=0;t>4,h[c++]=(15&r)<<4|i>>2,h[c++]=(3&i)<<6|63&o;return u}(e);return x(n,t)}return{base64:!0,data:e}},x=function(e,t){return"blob"===t?e instanceof Blob?e:new Blob([e]):e instanceof ArrayBuffer?e:e.buffer},P=String.fromCharCode(30);function j(){return new TransformStream({transform:function(e,t){!function(e,t){k&&e.data instanceof Blob?e.data.arrayBuffer().then(O).then(t):w&&(e.data instanceof ArrayBuffer||_(e.data))?t(O(e.data)):E(e,!1,(function(e){m||(m=new TextEncoder),t(m.encode(e))}))}(e,(function(n){var r,i=n.length;if(i<126)r=new Uint8Array(1),new DataView(r.buffer).setUint8(0,i);else if(i<65536){r=new Uint8Array(3);var o=new DataView(r.buffer);o.setUint8(0,126),o.setUint16(1,i)}else{r=new Uint8Array(9);var s=new DataView(r.buffer);s.setUint8(0,127),s.setBigUint64(1,BigInt(i))}e.data&&"string"!=typeof e.data&&(r[0]|=128),t.enqueue(r),t.enqueue(n)}))}})}function q(e){return e.reduce((function(e,t){return e+t.length}),0)}function D(e,t){if(e[0].length===t)return e.shift();for(var n=new Uint8Array(t),r=0,i=0;i1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:{};return e+"://"+this._hostname()+this._port()+this.opts.path+this._query(t)}},{key:"_hostname",value:function(){var e=this.opts.hostname;return-1===e.indexOf(":")?e:"["+e+"]"}},{key:"_port",value:function(){return this.opts.port&&(this.opts.secure&&Number(443!==this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""}},{key:"_query",value:function(e){var t=function(e){var t="";for(var n in e)e.hasOwnProperty(n)&&(t.length&&(t+="&"),t+=encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t}(e);return t.length?"?"+t:""}}]),i}(U),z="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),J=64,$={},Q=0,X=0;function G(e){var t="";do{t=z[e%J]+t,e=Math.floor(e/J)}while(e>0);return t}function Z(){var e=G(+new Date);return e!==K?(Q=0,K=e):e+"."+G(Q++)}for(;X0&&void 0!==arguments[0]?arguments[0]:{};return i(e,{xd:this.xd,cookieJar:this.cookieJar},this.opts),new se(this.uri(),e)}},{key:"doWrite",value:function(e,t){var n=this,r=this.request({method:"POST",data:e});r.on("success",t),r.on("error",(function(e,t){n.onError("xhr post error",e,t)}))}},{key:"doPoll",value:function(){var e=this,t=this.request();t.on("data",this.onData.bind(this)),t.on("error",(function(t,n){e.onError("xhr poll error",t,n)})),this.pollXhr=t}}]),s}(W),se=function(e){o(i,e);var n=l(i);function i(e,r){var o;return t(this,i),H(f(o=n.call(this)),r),o.opts=r,o.method=r.method||"GET",o.uri=e,o.data=void 0!==r.data?r.data:null,o.create(),o}return r(i,[{key:"create",value:function(){var e,t=this,n=F(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");n.xdomain=!!this.opts.xd;var r=this.xhr=new ne(n);try{r.open(this.method,this.uri,!0);try{if(this.opts.extraHeaders)for(var o in r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0),this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(o)&&r.setRequestHeader(o,this.opts.extraHeaders[o])}catch(e){}if("POST"===this.method)try{r.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(e){}try{r.setRequestHeader("Accept","*/*")}catch(e){}null===(e=this.opts.cookieJar)||void 0===e||e.addCookies(r),"withCredentials"in r&&(r.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(r.timeout=this.opts.requestTimeout),r.onreadystatechange=function(){var e;3===r.readyState&&(null===(e=t.opts.cookieJar)||void 0===e||e.parseCookies(r)),4===r.readyState&&(200===r.status||1223===r.status?t.onLoad():t.setTimeoutFn((function(){t.onError("number"==typeof r.status?r.status:0)}),0))},r.send(this.data)}catch(e){return void this.setTimeoutFn((function(){t.onError(e)}),0)}"undefined"!=typeof document&&(this.index=i.requestsCount++,i.requests[this.index]=this)}},{key:"onError",value:function(e){this.emitReserved("error",e,this.xhr),this.cleanup(!0)}},{key:"cleanup",value:function(e){if(void 0!==this.xhr&&null!==this.xhr){if(this.xhr.onreadystatechange=re,e)try{this.xhr.abort()}catch(e){}"undefined"!=typeof document&&delete i.requests[this.index],this.xhr=null}}},{key:"onLoad",value:function(){var e=this.xhr.responseText;null!==e&&(this.emitReserved("data",e),this.emitReserved("success"),this.cleanup())}},{key:"abort",value:function(){this.cleanup()}}]),i}(U);if(se.requestsCount=0,se.requests={},"undefined"!=typeof document)if("function"==typeof attachEvent)attachEvent("onunload",ae);else if("function"==typeof addEventListener){addEventListener("onpagehide"in I?"pagehide":"unload",ae,!1)}function ae(){for(var e in se.requests)se.requests.hasOwnProperty(e)&&se.requests[e].abort()}var ce="function"==typeof Promise&&"function"==typeof Promise.resolve?function(e){return Promise.resolve().then(e)}:function(e,t){return t(e,0)},ue=I.WebSocket||I.MozWebSocket,he="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase(),fe=function(e){o(i,e);var n=l(i);function i(e){var r;return t(this,i),(r=n.call(this,e)).supportsBinary=!e.forceBase64,r}return r(i,[{key:"name",get:function(){return"websocket"}},{key:"doOpen",value:function(){if(this.check()){var e=this.uri(),t=this.opts.protocols,n=he?{}:F(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(n.headers=this.opts.extraHeaders);try{this.ws=he?new ue(e,t,n):t?new ue(e,t):new ue(e)}catch(e){return this.emitReserved("error",e)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}}},{key:"addEventListeners",value:function(){var e=this;this.ws.onopen=function(){e.opts.autoUnref&&e.ws._socket.unref(),e.onOpen()},this.ws.onclose=function(t){return e.onClose({description:"websocket connection closed",context:t})},this.ws.onmessage=function(t){return e.onData(t.data)},this.ws.onerror=function(t){return e.onError("websocket error",t)}}},{key:"write",value:function(e){var t=this;this.writable=!1;for(var n=function(){var n=e[r],i=r===e.length-1;E(n,t.supportsBinary,(function(e){try{t.ws.send(e)}catch(e){}i&&ce((function(){t.writable=!0,t.emitReserved("drain")}),t.setTimeoutFn)}))},r=0;rMath.pow(2,21)-1){a.enqueue(b);break}i=l*Math.pow(2,32)+f.getUint32(4),r=3}else{if(q(n)e){a.enqueue(b);break}}}})}(Number.MAX_SAFE_INTEGER,e.socket.binaryType),r=t.readable.pipeThrough(n).getReader(),i=j();i.readable.pipeTo(t.writable),e.writer=i.writable.getWriter();!function t(){r.read().then((function(n){var r=n.done,i=n.value;r||(e.onPacket(i),t())})).catch((function(e){}))}();var o={type:"open"};e.query.sid&&(o.data='{"sid":"'.concat(e.query.sid,'"}')),e.writer.write(o).then((function(){return e.onOpen()}))}))})))}},{key:"write",value:function(e){var t=this;this.writable=!1;for(var n=function(){var n=e[r],i=r===e.length-1;t.writer.write(n).then((function(){i&&ce((function(){t.writable=!0,t.emitReserved("drain")}),t.setTimeoutFn)}))},r=0;r1&&void 0!==arguments[1]?arguments[1]:{};return t(this,a),(r=s.call(this)).binaryType="arraybuffer",r.writeBuffer=[],n&&"object"===e(n)&&(o=n,n=null),n?(n=ve(n),o.hostname=n.host,o.secure="https"===n.protocol||"wss"===n.protocol,o.port=n.port,n.query&&(o.query=n.query)):o.host&&(o.hostname=ve(o.host).host),H(f(r),o),r.secure=null!=o.secure?o.secure:"undefined"!=typeof location&&"https:"===location.protocol,o.hostname&&!o.port&&(o.port=r.secure?"443":"80"),r.hostname=o.hostname||("undefined"!=typeof location?location.hostname:"localhost"),r.port=o.port||("undefined"!=typeof location&&location.port?location.port:r.secure?"443":"80"),r.transports=o.transports||["polling","websocket","webtransport"],r.writeBuffer=[],r.prevBufferLen=0,r.opts=i({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},o),r.opts.path=r.opts.path.replace(/\/$/,"")+(r.opts.addTrailingSlash?"/":""),"string"==typeof r.opts.query&&(r.opts.query=function(e){for(var t={},n=e.split("&"),r=0,i=n.length;r1))return this.writeBuffer;for(var e,t=1,n=0;n=57344?n+=3:(r++,n+=4);return n}(e):Math.ceil(1.33*(e.byteLength||e.size))),n>0&&t>this.maxPayload)return this.writeBuffer.slice(0,n);t+=2}return this.writeBuffer}},{key:"write",value:function(e,t,n){return this.sendPacket("message",e,t,n),this}},{key:"send",value:function(e,t,n){return this.sendPacket("message",e,t,n),this}},{key:"sendPacket",value:function(e,t,n,r){if("function"==typeof t&&(r=t,t=void 0),"function"==typeof n&&(r=n,n=null),"closing"!==this.readyState&&"closed"!==this.readyState){(n=n||{}).compress=!1!==n.compress;var i={type:e,data:t,options:n};this.emitReserved("packetCreate",i),this.writeBuffer.push(i),r&&this.once("flush",r),this.flush()}}},{key:"close",value:function(){var e=this,t=function(){e.onClose("forced close"),e.transport.close()},n=function n(){e.off("upgrade",n),e.off("upgradeError",n),t()},r=function(){e.once("upgrade",n),e.once("upgradeError",n)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(function(){e.upgrading?r():t()})):this.upgrading?r():t()),this}},{key:"onError",value:function(e){a.priorWebsocketSuccess=!1,this.emitReserved("error",e),this.onClose("transport error",e)}},{key:"onClose",value:function(e,t){"opening"!==this.readyState&&"open"!==this.readyState&&"closing"!==this.readyState||(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),"function"==typeof removeEventListener&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",e,t),this.writeBuffer=[],this.prevBufferLen=0)}},{key:"filterUpgrades",value:function(e){for(var t=[],n=0,r=e.length;n=0&&t.num1?t-1:0),r=1;r1?n-1:0),i=1;in._opts.retries&&(n._queue.shift(),t&&t(e));else if(n._queue.shift(),t){for(var i=arguments.length,o=new Array(i>1?i-1:0),s=1;s0&&void 0!==arguments[0]&&arguments[0];if(this.connected&&0!==this._queue.length){var t=this._queue[0];t.pending&&!e||(t.pending=!0,t.tryCount++,this.flags=t.flags,this.emit.apply(this,t.args))}}},{key:"packet",value:function(e){e.nsp=this.nsp,this.io._packet(e)}},{key:"onopen",value:function(){var e=this;"function"==typeof this.auth?this.auth((function(t){e._sendConnectPacket(t)})):this._sendConnectPacket(this.auth)}},{key:"_sendConnectPacket",value:function(e){this.packet({type:Be.CONNECT,data:this._pid?i({pid:this._pid,offset:this._lastOffset},e):e})}},{key:"onerror",value:function(e){this.connected||this.emitReserved("connect_error",e)}},{key:"onclose",value:function(e,t){this.connected=!1,delete this.id,this.emitReserved("disconnect",e,t),this._clearAcks()}},{key:"_clearAcks",value:function(){var e=this;Object.keys(this.acks).forEach((function(t){if(!e.sendBuffer.some((function(e){return String(e.id)===t}))){var n=e.acks[t];delete e.acks[t],n.withError&&n.call(e,new Error("socket has been disconnected"))}}))}},{key:"onpacket",value:function(e){if(e.nsp===this.nsp)switch(e.type){case Be.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case Be.EVENT:case Be.BINARY_EVENT:this.onevent(e);break;case Be.ACK:case Be.BINARY_ACK:this.onack(e);break;case Be.DISCONNECT:this.ondisconnect();break;case Be.CONNECT_ERROR:this.destroy();var t=new Error(e.data.message);t.data=e.data.data,this.emitReserved("connect_error",t)}}},{key:"onevent",value:function(e){var t=e.data||[];null!=e.id&&t.push(this.ack(e.id)),this.connected?this.emitEvent(t):this.receiveBuffer.push(Object.freeze(t))}},{key:"emitEvent",value:function(e){if(this._anyListeners&&this._anyListeners.length){var t,n=y(this._anyListeners.slice());try{for(n.s();!(t=n.n()).done;){t.value.apply(this,e)}}catch(e){n.e(e)}finally{n.f()}}p(s(a.prototype),"emit",this).apply(this,e),this._pid&&e.length&&"string"==typeof e[e.length-1]&&(this._lastOffset=e[e.length-1])}},{key:"ack",value:function(e){var t=this,n=!1;return function(){if(!n){n=!0;for(var r=arguments.length,i=new Array(r),o=0;o0&&e.jitter<=1?e.jitter:0,this.attempts=0}Ie.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var t=Math.random(),n=Math.floor(t*this.jitter*e);e=0==(1&Math.floor(10*t))?e-n:e+n}return 0|Math.min(e,this.max)},Ie.prototype.reset=function(){this.attempts=0},Ie.prototype.setMin=function(e){this.ms=e},Ie.prototype.setMax=function(e){this.max=e},Ie.prototype.setJitter=function(e){this.jitter=e};var Fe=function(n){o(s,n);var i=l(s);function s(n,r){var o,a;t(this,s),(o=i.call(this)).nsps={},o.subs=[],n&&"object"===e(n)&&(r=n,n=void 0),(r=r||{}).path=r.path||"/socket.io",o.opts=r,H(f(o),r),o.reconnection(!1!==r.reconnection),o.reconnectionAttempts(r.reconnectionAttempts||1/0),o.reconnectionDelay(r.reconnectionDelay||1e3),o.reconnectionDelayMax(r.reconnectionDelayMax||5e3),o.randomizationFactor(null!==(a=r.randomizationFactor)&&void 0!==a?a:.5),o.backoff=new Ie({min:o.reconnectionDelay(),max:o.reconnectionDelayMax(),jitter:o.randomizationFactor()}),o.timeout(null==r.timeout?2e4:r.timeout),o._readyState="closed",o.uri=n;var c=r.parser||je;return o.encoder=new c.Encoder,o.decoder=new c.Decoder,o._autoConnect=!1!==r.autoConnect,o._autoConnect&&o.open(),o}return r(s,[{key:"reconnection",value:function(e){return arguments.length?(this._reconnection=!!e,this):this._reconnection}},{key:"reconnectionAttempts",value:function(e){return void 0===e?this._reconnectionAttempts:(this._reconnectionAttempts=e,this)}},{key:"reconnectionDelay",value:function(e){var t;return void 0===e?this._reconnectionDelay:(this._reconnectionDelay=e,null===(t=this.backoff)||void 0===t||t.setMin(e),this)}},{key:"randomizationFactor",value:function(e){var t;return void 0===e?this._randomizationFactor:(this._randomizationFactor=e,null===(t=this.backoff)||void 0===t||t.setJitter(e),this)}},{key:"reconnectionDelayMax",value:function(e){var t;return void 0===e?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,null===(t=this.backoff)||void 0===t||t.setMax(e),this)}},{key:"timeout",value:function(e){return arguments.length?(this._timeout=e,this):this._timeout}},{key:"maybeReconnectOnOpen",value:function(){!this._reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()}},{key:"open",value:function(e){var t=this;if(~this._readyState.indexOf("open"))return this;this.engine=new ge(this.uri,this.opts);var n=this.engine,r=this;this._readyState="opening",this.skipReconnect=!1;var i=qe(n,"open",(function(){r.onopen(),e&&e()})),o=function(n){t.cleanup(),t._readyState="closed",t.emitReserved("error",n),e?e(n):t.maybeReconnectOnOpen()},s=qe(n,"error",o);if(!1!==this._timeout){var a=this._timeout,c=this.setTimeoutFn((function(){i(),o(new Error("timeout")),n.close()}),a);this.opts.autoUnref&&c.unref(),this.subs.push((function(){t.clearTimeoutFn(c)}))}return this.subs.push(i),this.subs.push(s),this}},{key:"connect",value:function(e){return this.open(e)}},{key:"onopen",value:function(){this.cleanup(),this._readyState="open",this.emitReserved("open");var e=this.engine;this.subs.push(qe(e,"ping",this.onping.bind(this)),qe(e,"data",this.ondata.bind(this)),qe(e,"error",this.onerror.bind(this)),qe(e,"close",this.onclose.bind(this)),qe(this.decoder,"decoded",this.ondecoded.bind(this)))}},{key:"onping",value:function(){this.emitReserved("ping")}},{key:"ondata",value:function(e){try{this.decoder.add(e)}catch(e){this.onclose("parse error",e)}}},{key:"ondecoded",value:function(e){var t=this;ce((function(){t.emitReserved("packet",e)}),this.setTimeoutFn)}},{key:"onerror",value:function(e){this.emitReserved("error",e)}},{key:"socket",value:function(e,t){var n=this.nsps[e];return n?this._autoConnect&&!n.active&&n.connect():(n=new Ue(this,e,t),this.nsps[e]=n),n}},{key:"_destroy",value:function(e){for(var t=0,n=Object.keys(this.nsps);t=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{var n=this.backoff.duration();this._reconnecting=!0;var r=this.setTimeoutFn((function(){t.skipReconnect||(e.emitReserved("reconnect_attempt",t.backoff.attempts),t.skipReconnect||t.open((function(n){n?(t._reconnecting=!1,t.reconnect(),e.emitReserved("reconnect_error",n)):t.onreconnect()})))}),n);this.opts.autoUnref&&r.unref(),this.subs.push((function(){e.clearTimeoutFn(r)}))}}},{key:"onreconnect",value:function(){var e=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",e)}}]),s}(U),Me={};function Ve(t,n){"object"===e(t)&&(n=t,t=void 0);var r,i=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=arguments.length>2?arguments[2]:void 0,r=e;n=n||"undefined"!=typeof location&&location,null==e&&(e=n.protocol+"//"+n.host),"string"==typeof e&&("/"===e.charAt(0)&&(e="/"===e.charAt(1)?n.protocol+e:n.host+e),/^(https?|wss?):\/\//.test(e)||(e=void 0!==n?n.protocol+"//"+e:"https://"+e),r=ve(e)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port="80":/^(http|ws)s$/.test(r.protocol)&&(r.port="443")),r.path=r.path||"/";var i=-1!==r.host.indexOf(":")?"["+r.host+"]":r.host;return r.id=r.protocol+"://"+i+":"+r.port+t,r.href=r.protocol+"://"+i+(n&&n.port===r.port?"":":"+r.port),r}(t,(n=n||{}).path||"/socket.io"),o=i.source,s=i.id,a=i.path,c=Me[s]&&a in Me[s].nsps;return n.forceNew||n["force new connection"]||!1===n.multiplex||c?r=new Fe(o,n):(Me[s]||(Me[s]=new Fe(o,n)),r=Me[s]),i.query&&!n.query&&(n.query=i.queryKey),r.socket(i.path,n)}return i(Ve,{Manager:Fe,Socket:Ue,io:Ve,connect:Ve}),Ve})); -//# sourceMappingURL=socket.io.min.js.map diff --git a/Server/versionNum.py b/Server/versionNum.py deleted file mode 100644 index 123cfbd..0000000 --- a/Server/versionNum.py +++ /dev/null @@ -1,67 +0,0 @@ -from __future__ import annotations -class VersionNumber: - def __init__(self,major:int,minor:int,patch:int,extra:str): - self.major = major - self.minor = minor - self.patch = patch - self.extra = extra - - # From String like "x.y.z-extra" - @staticmethod - def fromString(verString:str) -> VersionNumber: - numList = verString.split(".") - major = int(numList[0]) - minor = int(numList[1]) - patch = int(numList[2].split("-")[0]) - extra = numList[2].split("-")[1] - return VersionNumber(major,minor,patch,extra) - - - def clone(verNumIn:VersionNumber) -> VersionNumber: - return VersionNumber(verNumIn.major,verNumIn.minor,verNumIn.patch,verNumIn.extra) - - def __str__(self) -> str: - returnStr = f"v{self.major}.{self.minor}.{self.patch}" - if(self.extra): - returnStr += f"-{self.extra}" - return returnStr - - def __eq__(self,comp) -> bool: - if type(comp) == VersionNumber: - return self.major == comp.major and self.minor == comp.minor and self.patch == comp.patch and self.extra == comp.extra - elif type(comp) == str: - return self == VersionNumber.fromString(comp) - elif type(comp) == type(None): - return False - else: - raise TypeError - - def __gt__(self,comp): - if type(comp) == VersionNumber: - if(self.major > comp.major): - return True - elif(self.major == comp.major and self.minor > comp.minor): - return True - elif(self.major == comp.major and self.minor == comp.minor and self.patch > comp.patch): - return True - return False - elif type(comp) == str: - return self > VersionNumber.fromString(comp) - else: - raise TypeError - - def __ge__(self,comp): - return self > comp or self == comp - -if __name__ == "__main__": - x = VersionNumber(1,2,4,"alpha") - y = VersionNumber.fromString("1.2.3-beta") - z = VersionNumber.clone(x) - print(x) - print(y) - print(z) - print(f"X == Y: {x==y}") - print(f"X > Y: {x>y}") - print(f"Y < X: {y= Y: {z>=y}") - print(f"Z <= Y: {z<=y}") diff --git a/Server/webbyBits.py b/Server/webbyBits.py index 74f98df..0e0560f 100644 --- a/Server/webbyBits.py +++ b/Server/webbyBits.py @@ -1,59 +1,56 @@ -# import eventlet -# eventlet.monkey_patch() +import eventlet +eventlet.monkey_patch() from flask import Flask -from flask import request,render_template +from flask import request +from flask_cors import CORS from flask_socketio import SocketIO import sqlite3 as sql -import vlc,threading,random,argparse,dotenv,os,hashlib,string,getpass -from versionNum import VersionNumber - -# So i'm famously bad at following Semantic versioning, we're gonna see how this goes -REL_VER_NUM = VersionNumber(0,0,2,"alpha") +import vlc,threading,time,random,argparse,dotenv,os,hashlib,string # Argparse Stuff parser=argparse.ArgumentParser(description="Options for the Webby Bits") -parser.add_argument('-a','--admin',help="Set as True to be prompted to enter an AdminPassword",default=False) +# 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="") args = parser.parse_args() dotenv.load_dotenv() portTheUserPicked=os.getenv("SERVER_PORT") ERR_NO_ADMIN = ({"error":"no-admin","data":None},401) ERR_200 = ({"error":"OK","data":None},200) -ERR_MISSING_ARGS = ({"error":"Request missing required arguments","data":None},400) -if bool(args.admin) and args.admin.lower() != "false": - ADMIN_PASS = hashlib.sha256(bytes(getpass.getpass("Enter AdminPass: "),'utf-8')).hexdigest() +ERR_MISSING_ARGS = ({"error":"Request missing required arguments","data":None}),400 +if args.admin: + ADMIN_PASS = hashlib.sha256(bytes(args.admin,'utf-8')).hexdigest() else: tempPass = ''.join(random.choices(string.ascii_letters + string.digits +"?"+"!",k=20)) print("No adminPass was set, the auto generated one is: "+tempPass) ADMIN_PASS = hashlib.sha256(bytes(tempPass,'utf-8')).hexdigest() # True = everyone, False = admin only. Change in client while in use. -# play-pause,skip,addsong,partymode,volume,add duplicates in order +# play-pause,skip,addsong,partymode,volume in order controlPerms = { "PP":True, "SK":True, "AS":True, "PM":True, "VOL":True, - "DUP":True + "DUP":True # Not implemented, allow duplicate songs in queue } fileofDB = sql.connect("songDatabase.db") songDatabase = fileofDB.cursor() #song directory -try: - songDatabase.execute("SELECT * FROM meta WHERE id='songDirectory';") - soundLocation = songDatabase.fetchall()[0][1] -except sql.OperationalError: - print("No Database Found, try running databaseGenerator.py") - os._exit(1) +songDatabase.execute("SELECT * FROM meta WHERE id='songDirectory';") +soundLocation = songDatabase.fetchall()[0][1] if soundLocation[-1] == "/" or soundLocation[-1] == "\\": pass elif "/" in soundLocation: soundLocation += "/" else: soundLocation += "\\" +#Create Virtual table for searching +#I'm not sure why i don't do this in the databaseGenerator, but it also takes like 3 seconds so i'm not messing with it rn + #Initializing all the global stuff random.seed() global partyMode @@ -69,7 +66,10 @@ player = vlcInstance.media_player_new() # for client side volume to work as well as possible, set system volume to 100 and control in app player.audio_set_volume(100) app = Flask(__name__) -socketio = SocketIO(app) +# because you are POSTing from another domain to this one, you need CORS +CORS(app) +# Replace the star with the frontend domain if you dislike being hacked +socketio = SocketIO(app, cors_allowed_origins="*") def queueSong(song): with playlistLock: @@ -105,7 +105,7 @@ def playQueuedSongs(): counter+=1 if(counter > 2): playingState = str(player.get_state()) == "State.Playing" - socketio.emit('timeUpdate',{"elapsedTime":player.get_time()/1000,"playingState":playingState,"songLength":player.get_length()/1000}) + socketio.emit('timeUpdate',{"elapsedTime":player.get_time()/1000,"playingState":playingState}) counter = 0 playerState = str(player.get_state()) endStates = ["State.Ended","State.Stopped","State.NothingSpecial"] @@ -140,16 +140,12 @@ def playQueuedSongs(): # check for new songs every second # I just didn't want to eat too much processing looping # this also has another useful affect that skips get "queued" to only 1 per second, that way somebody usually can't skip twice accidentally - socketio.sleep(1) + time.sleep(1) @socketio.on("connect") def handleConnect(): pass -@app.route("/",methods=['GET']) -def returnStaticFile(): - return render_template("index.html",REL_VER_NUM=str(REL_VER_NUM)) - @app.route("/controls", methods=['POST']) def playerControls(): # recieve control inputs (play/pause and skip) from the webUI @@ -158,7 +154,7 @@ def playerControls(): recieveData=request.get_json(force=True) try: if recieveData["control"] == "play-pause": - if ADMIN_PASS == request.headers["Jukebox-Auth"] or controlPerms["PP"]: + if ADMIN_PASS == recieveData['password'] or controlPerms["PP"]: playingState = str(player.get_state())=="State.Playing" player.pause() return {"error":"ok","data":{"playingState":not(playingState)}},200 @@ -166,14 +162,14 @@ def playerControls(): playingState = str(player.get_state())=="State.Playing" return {"error":"Admin Restricted Action","data":{"playingState":playingState}},401 elif recieveData["control"] == "skip": - if ADMIN_PASS == request.headers["Jukebox-Auth"] or controlPerms["SK"]: + if ADMIN_PASS == recieveData['password'] or controlPerms["SK"]: skipNow = True return ERR_200 else: return ERR_NO_ADMIN # Maybe i should have put this next one in the "settings" section elif recieveData["control"] == "clear": - if ADMIN_PASS == request.headers["Jukebox-Auth"]: # this is only ever allowed with the adminpassword + if ADMIN_PASS == recieveData['password']: # this is only ever allowed with the adminpassword with playlistLock: playlist.clear() return ERR_200 @@ -184,75 +180,65 @@ def playerControls(): except KeyError: return ERR_MISSING_ARGS -@app.route("/settings", methods=['POST','GET']) +@app.route("/settings", methods=['POST']) def settingsControl(): global controlPerms # set the volume and partymode global partyMode global player - if (request.method == 'GET'): - return {"error":"ok","data":{"partymode":partyMode,"volume":player.audio_get_volume(),"admin":controlPerms}},200 - elif (request.method == 'POST'): - recieveData = request.get_json(force=True) - try: - if recieveData["setting"] == "volume": - if ADMIN_PASS == request.headers["Jukebox-Auth"] or controlPerms["VOL"]: - volumeLevel = int(recieveData["level"]) - if(volumeLevel <= 100 and volumeLevel >= 0): - volumePassed = player.audio_set_volume(volumeLevel) - if(volumePassed == 0): - # only emit a signal i the volume really changed - socketio.emit("settingsChange",{"settingToChange":"volume","newData":volumeLevel}) - return {"error":"ok","data":{"volumePassed":volumePassed}},200 - else: - return {"error":"Invalid volume level","data":None},422 + recieveData = request.get_json(force=True) + try: + if recieveData["setting"] == "volume": + if ADMIN_PASS == recieveData['password'] or controlPerms["VOL"]: + volumeLevel = int(recieveData["level"]) + if(volumeLevel <= 100 and volumeLevel >= 0): + volumePassed = player.audio_set_volume(volumeLevel) + if(volumePassed == 0): + # only emit a signal i the volume really changed + socketio.emit("settingsChange",{"settingToChange":"volume","newData":volumeLevel}) + return {"error":"ok","data":{"volumePassed":volumePassed}},200 else: - return ERR_NO_ADMIN - elif recieveData["setting"] == "partymode-toggle": - if ADMIN_PASS == request.headers["Jukebox-Auth"] or controlPerms["PM"]: - partyMode = not(partyMode) - partyModeStr = "On" if partyMode else "Off" - socketio.emit("settingsChange",{"settingToChange":"partymode","newData":partyModeStr}) - return ERR_200 - else: - return ERR_NO_ADMIN - elif recieveData["setting"] == "perms": - if ADMIN_PASS == request.headers["Jukebox-Auth"]: - controlPerms = recieveData["admin"] - # print(recieveData["admin"]) - socketio.emit("settingsChange",{"settingToChange":"perms","newData":controlPerms}) - return ERR_200 - else: - return ERR_NO_ADMIN + return {"error":"Invalid volume level","data":None},422 else: - return {"error":"Not a valid setting","data":None},400 - except KeyError as e: - print(f"Error: {e}") - return {"error":"Incorrect Data Sent","data":None},400 + return ERR_NO_ADMIN + elif recieveData["setting"] == "partymode-toggle": + if ADMIN_PASS == recieveData['password'] or controlPerms["PM"]: + partyMode = not(partyMode) + partyModeStr = "On" if partyMode else "Off" + socketio.emit("settingsChange",{"settingToChange":"partymode","newData":partyModeStr}) + return ERR_200 + else: + return ERR_NO_ADMIN + elif recieveData["setting"] == "perms": + if ADMIN_PASS == recieveData["password"]: + controlPerms = recieveData["admin"] + # print(recieveData["admin"]) + socketio.emit("settingsChange",{"settingToChange":"perms","newData":controlPerms}) + return ERR_200 + else: + return ERR_NO_ADMIN + elif recieveData["setting"] == "getsettings": + # 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 + else: + return {"error":"Not a valid setting","data":None},400 + except: + return ERR_MISSING_ARGS -@app.route("/search", methods=['GET']) +@app.route("/search", methods=['POST']) def searchSongDB(): - recieveData = request.args.get("query") - page = int(request.args.get("page")) - if not(page): - page = 1 + recieveData=request.get_json(force=True) fileofDB = sql.connect("songDatabase.db") songDatabase = fileofDB.cursor() try: results = [] # print(recieveData["search"]) - if (recieveData == None or recieveData == ""): + if (recieveData['search'] == ""): songDatabase.execute("SELECT * FROM virtualSongs") results = songDatabase.fetchall() else: - songDatabase.execute("SELECT * FROM virtualSongs WHERE virtualSongs MATCH ?",['"' + recieveData +'"']) + songDatabase.execute("SELECT * FROM virtualSongs WHERE virtualSongs MATCH ?",['"' + recieveData['search']+'"']) results = songDatabase.fetchall() - pages = (len(results)//20)+1 - if(page>0): - # Numbers <0 use old rendering - inBound = 20*(page-1) - outBound = 20*page - results = results[inBound:outBound] tempdata = {} # this is a temporary solution so i dont have to change the client for i in results: @@ -265,7 +251,10 @@ def searchSongDB(): } fileofDB.close() - return {"error":"ok","data":{"songsobj":tempdata,"pages":pages}},200 + return {"error":"ok","data":tempdata},200 + except KeyError: + fileofDB.close() + return ERR_MISSING_ARGS except sql.OperationalError as e: print(e) fileofDB.close() @@ -276,9 +265,9 @@ def searchSongDB(): def songadd(): recieveData=request.get_json(force=True) try: - if (ADMIN_PASS == request.headers["Jukebox-Auth"]) or controlPerms["AS"]: + if (ADMIN_PASS == recieveData['password']) or controlPerms["AS"]: # Password exists and is correct, or it's not restricted - if not(controlPerms["DUP"]) and (recieveData['song'] in playlist) and not(ADMIN_PASS == request.headers["Jukebox-Auth"]): + if not(controlPerms["DUP"]) and (recieveData['song'] in playlist) and not(ADMIN_PASS == recieveData['password']): return {"error":"This song is already in the queue, hang on!","data":None},409 else: queueSong(recieveData['song']) @@ -290,7 +279,7 @@ def songadd(): print(e) return ERR_MISSING_ARGS -@app.route("/playlist", methods=["GET"]) +@app.route("/playlist", methods=["POST"]) def getPlaylist(): global songNext fileofDB = sql.connect("songDatabase.db") @@ -335,6 +324,5 @@ if __name__ == "__main__": queueThread = threading.Thread(target=playQueuedSongs) queueThread.daemon = True queueThread.start() - print(f"PartyJukebox {REL_VER_NUM} running on port {portTheUserPicked}") socketio.run(app=app,host='0.0.0.0', port=portTheUserPicked) \ No newline at end of file diff --git a/readme.md b/readme.md index 6ccc66c..2589f25 100644 --- a/readme.md +++ b/readme.md @@ -4,12 +4,13 @@ You can use `--help` on any of the python files to see all the properties that can be changed at runtime ## Purpose The **Party Jukebox** is a program that allows many people to add music, skip songs, play, and pause from any web device to the same device and playlist. \ -This was created for a personal use case for parties, and is a simple solution to have a collective playlist for local audio files. \ -The main advantage compared to doing something similar using Spotify or another streaming service is that you can limit the songs that can be played to your selection. Songs can be chosen, but only from a list. +This was created for a personal use case for parties, and is a simple, (mostly) functional solution to have a collective playlist for local mp3 files. \ +The main advantage compared to doing something similar using Spotify is that you can limit the songs that can be played to your selection. Songs can be chosen, but only from a list. ## Basic Setup ### Client Setup: -The client is a web application hosted by the flask app running the audio player. -* You can add `?darkmode=(true/false)` to the client URL to set the default colour scheme, but this will be overwritten by the user's saved choice if they change it themselves +The client is a web application that can be hosted on any server, it need not be the same device running the music player. +* If the app is being setup for a large group, you can distribute the url (via QR code, for example) with `?ip=YOURSERVERHOSTNAME:19054` set as an attribute after the url. +* You can also add `?darkmode=(true/false)` to set the default colour scheme, but this will be overwritten by the users saved choice in the cookie if they change it themselves ### Server Setup: **Pre-setup:** If you want the songs to have art associated with them, it is all hosted on and retrieved from LastFM, and you will need to sign up for a developer app, and put your key in the database generator \ \ @@ -22,20 +23,18 @@ webbyBits.py .env ``` -1. Place audio files in the `sound/` folder - - Supports flac, mp3, and wav files +1. Place mp3 files in the `sound/` folder 2. Rename `example.env` to `.env` and... - Set the location where your audio files are (Default: `./sound/`) - Set the LastFM API key (Optional) - - Change the port of the app (Default: `19054` ) + - Change the port of the webbybits server (Default: `19054` ) 3. Run `databaseGenerator.py` (Will try to use LastFM API key) - * *The `databaseGenerator.py` will index all audio files, and save the information to `songDatabase.db`* - * *If getting images, this process may take a long time with a large amount of audio files* + * *The `databaseGenerator.py` will index all mp3 files, and save the information to `songDatabase.db`* + * *If getting images, this process may take a long time with a large amount of mp3 files* 4. Run `webbyBits.py` * *The port can be customized by editing the `.env` file* - * *You can add an admin password at runtime with* `-a True` *as an atribute* + * *You can add an admin password at runtime with* `-a AdminPass` *as an atribute* * ***NOTE: Do not reuse ANY password for this, it is hashed but 100% unsecure. The best option is just a random string you write down once*** - * You will be prompted in console for a password to be used * If this attribute isn't included a random string will be generated as the admin password * This is intended for protecting certain features for small closed events, not for public security @@ -46,8 +45,8 @@ Read on for specific information on each piece of the app. ## Details These are specific details on each section of the app, and how to use them ### Server: -- `sound/` contains all audio files by default -- `databaseGenerator.py` scans through audio files and gets information about them +- `sound/` contains all mp3 files by default +- `databaseGenerator.py` scans through mp3 files and gets information about them - `Filename, Title, Artist, Art, Length` are all saved - *If the title and artist are not in the file metadata, it looks for a format of* `TITLE_ARTIST.mp3` *then of* `ARTIST - TITLE.mp3` *and otherwise defaults to the file name as the title, and no artist* - Art is retrieved from LastFM @@ -98,15 +97,14 @@ From left to right: The exact process of the password's plaintext scope is as follows -- On the server, you type in the password on the server in the console, the python script takes that input directly, hashes it, then stores that hash as a variable. The plaintext could be in memory, but it's not accessible in the code after that initial hashing. If you typed your own password, it won't be visible in the console history after it is typed. +- On the server, you type in the password on the server in the console, the python script takes that plaintext, hashes it, then stores that hash as a variable. The plaintext is also technically a variable, but it's not accessed after that initial hashing. (It's also going to be visible in your console history) -- On the client, you type in the password and press enter. A function reads the value of the password box, saves the hash of that password to a variable, and sends it with all your requests. The plaintext is still stored in the input box, but if you delete it and don't press enter on the box again, the hash will be stored without keeping the plaintext. (I may change this behaviour so this box auto-clears when enter is pressed) +- On the client, you type in the password and press enter. A function reads the value of the password box, saves the hash of that password to a variable, and sends it with all your requests. The plaintext is still stored in the inputbox, but if you delete it and don't press enter on the box again, the hash will be stored without keeping the plaintext. (I may change this behaviour so this box auto-clears when enter is pressed, maybe) -None of this is "secure", but it's better than sending plaintext passwords, which is what I was doing before. Hypothetically somebody who intercepted any packets with the password can't get back the original plaintext, just the hash. +None of this is "secure", but it's better than sending plaintext passwords, which is what I was doing before. Hypothetically somebody who intercepted your packet where you sent the password can't get back the original plaintext, just the hash. ## External Credits - QR Code Generator: JS file found [here](https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js) - - Socket.io: JS file found [here](https://cdn.socket.io/4.7.5/socket.io.min.js) - - SHA256 over http: JS file found [here](https://cdnjs.cloudflare.com/ajax/libs/js-sha256/0.11.0/sha256.min.js) + - Cookie Popup: JS file found [here](https://cookieconsent.popupsmart.com/src/js/popper.js) *See `LICENSE.md` for redistribution and editing details.* diff --git a/requirements.txt b/requirements.txt index 4863182..ac8054e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,6 @@ charset-normalizer==3.4.4 click==8.3.1 colorama==0.4.6 dotenv==0.9.9 -eventlet Flask==3.1.2 flask-cors==6.0.2 Flask-SocketIO==5.6.0 diff --git a/wishlist.md b/wishlist.md index 13d6bfb..6b1cbe5 100644 --- a/wishlist.md +++ b/wishlist.md @@ -1,20 +1,14 @@ # Wishlist *Features I would like to add, will be completed in any order* -- [ ] Pages of song results, to avoid very long pages and large data being sent -- [ ] RESTful design - - [ ] Change all necesary POSTs to GET,DELETE (probably not PUT) - - [ ] Write an api layout - - Despite the fact this isn't necesary (nobody but the app should access any url but root) it's probably still a good idea. It's going to be very simple anyway - [ ] Loading indicator while awaiting server stuff - [ ] Refactoring existing code - [x] Remove old comments - [ ] Update the SQL -> Server -> Client pipeline when searching and building playlist - - Moving to mongo might make more sense to maintain a dictionary/JSON like format, but that needs a server - [ ] Verify all if-else sequences are correct and not redundant - [ ] Security Updates - [x] `.env` file for the api keys and other runtime info to be set, rather than in the `.py` files - [x] Hashing rather than plaintext sending passwords (that way at least the password text itself isn't transmitted over the network) - - [ ] Actually use TLS, for posting + - [ ] Actually use SSL, for posting (CORS seems like an issue) - [ ] Accessibility - [ ] Better use of semantic HTML tags - [ ] Full keyboard control (tab, enter to select, tab between control buttons)