mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Extension now gives feedback about incorrect configuration
This commit is contained in:
parent
5cedde41a1
commit
95e80833cc
11
database.py
11
database.py
@ -100,6 +100,17 @@ def getTrackID(artists,title):
|
||||
## HTTP requests
|
||||
####
|
||||
|
||||
@route("/test")
|
||||
def test_server():
|
||||
apikey = request.query.get("key")
|
||||
response.set_header("Access-Control-Allow-Origin","*")
|
||||
if not (checkAPIkey(apikey)):
|
||||
response.status = 403
|
||||
return "Wrong or Missing API key"
|
||||
|
||||
else:
|
||||
response.status = 204
|
||||
return
|
||||
|
||||
@route("/scrobbles")
|
||||
def get_scrobbles():
|
||||
|
@ -4,13 +4,15 @@
|
||||
<head>
|
||||
<title>Wat</title>
|
||||
<script type="text/javascript" src="settings.js"></script>
|
||||
<meta charset="UTF-8">
|
||||
</head>
|
||||
<body>
|
||||
<body style="width:300px">
|
||||
<div id="wat">
|
||||
<p>Server:</p>
|
||||
<input type="text" id="serverurl" value="http://localhost:42010" />
|
||||
<p>API key:</p>
|
||||
<input type="text" id="apikey" />
|
||||
<span id="checkmark_url"></span> <span style="line-height:20px">Server:</span><br />
|
||||
<input style="width:270px" type="text" id="serverurl" value="http://localhost:42010" />
|
||||
<br /><br />
|
||||
<span id="checkmark_key"></span> <span style="line-height:20px">API key:</span><br />
|
||||
<input style="width:270px" type="text" id="apikey" />
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -3,14 +3,21 @@ document.addEventListener("DOMContentLoaded",function() {
|
||||
document.getElementById("serverurl").addEventListener("input",updateServer);
|
||||
document.getElementById("apikey").addEventListener("input",updateAPIKey);
|
||||
|
||||
document.getElementById("serverurl").addEventListener("change",checkServer);
|
||||
document.getElementById("apikey").addEventListener("change",checkServer);
|
||||
|
||||
|
||||
chrome.storage.local.get({"serverurl":"http://localhost:42010"},function(result) {
|
||||
document.getElementById("serverurl").value = result["serverurl"]
|
||||
checkServer()
|
||||
});
|
||||
chrome.storage.local.get({"apikey":"BlackPinkInYourArea"},function(result) {
|
||||
document.getElementById("apikey").value = result["apikey"]
|
||||
checkServer()
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
@ -19,16 +26,52 @@ function updateServer() {
|
||||
|
||||
text = document.getElementById("serverurl").value
|
||||
|
||||
if (!text.startsWith("http://") & !text.startsWith("https://")) {
|
||||
document.getElementById("serverurl").style.backgroundColor = "pink";
|
||||
}
|
||||
else {
|
||||
document.getElementById("serverurl").style.backgroundColor = "white";
|
||||
chrome.storage.local.set({"serverurl":text})
|
||||
}
|
||||
|
||||
chrome.storage.local.set({"serverurl":text})
|
||||
}
|
||||
|
||||
function updateAPIKey() {
|
||||
text = document.getElementById("apikey").value
|
||||
chrome.storage.local.set({"apikey":text})
|
||||
}
|
||||
|
||||
function checkServer() {
|
||||
url = document.getElementById("serverurl").value + "/db/test?key=" + document.getElementById("apikey").value
|
||||
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = createCheckmarks;
|
||||
try {
|
||||
xhttp.open("GET",url,true);
|
||||
xhttp.send();
|
||||
}
|
||||
catch (e) {
|
||||
//document.getElementById("checkmark_url").innerHTML = "❌"
|
||||
//document.getElementById("checkmark_key").innerHTML = "❌"
|
||||
document.getElementById("serverurl").style.backgroundColor = "red"
|
||||
document.getElementById("apikey").style.backgroundColor = "red"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function createCheckmarks() {
|
||||
if (this.readyState == 4) {
|
||||
if (this.status == 204) {
|
||||
//document.getElementById("checkmark_url").innerHTML = "✔️"
|
||||
//document.getElementById("checkmark_key").innerHTML = "✔️"
|
||||
document.getElementById("serverurl").style.backgroundColor = "lawngreen"
|
||||
document.getElementById("apikey").style.backgroundColor = "lawngreen"
|
||||
}
|
||||
else if (this.status == 403) {
|
||||
//document.getElementById("checkmark_url").innerHTML = "✔️"
|
||||
//document.getElementById("checkmark_key").innerHTML = "❌"
|
||||
document.getElementById("serverurl").style.backgroundColor = "lawngreen"
|
||||
document.getElementById("apikey").style.backgroundColor = "red"
|
||||
}
|
||||
else {
|
||||
//document.getElementById("checkmark_url").innerHTML = "❌"
|
||||
//document.getElementById("checkmark_key").innerHTML = "❌"
|
||||
document.getElementById("serverurl").style.backgroundColor = "red"
|
||||
document.getElementById("apikey").style.backgroundColor = "red"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
server.py
13
server.py
@ -31,11 +31,16 @@ def database_get(pth):
|
||||
keystring = "?"
|
||||
for k in keys:
|
||||
keystring += urllib.parse.quote(k) + "=" + urllib.parse.quote(keys[k]) + "&"
|
||||
contents = urllib.request.urlopen("http://localhost:" + str(DATABASE_PORT) + "/" + pth + keystring).read()
|
||||
response.content_type = "application/json"
|
||||
response.set_header("Access-Control-Allow-Origin","*")
|
||||
#print("Returning " + "http://localhost:" + str(DATABASE_PORT) + "/" + pth)
|
||||
return contents
|
||||
try:
|
||||
proxyresponse = urllib.request.urlopen("http://localhost:" + str(DATABASE_PORT) + "/" + pth + keystring)
|
||||
contents = proxyresponse.read()
|
||||
response.status = proxyresponse.getcode()
|
||||
response.content_type = "application/json"
|
||||
return contents
|
||||
except HTTPError as e:
|
||||
response.status = e.code
|
||||
return
|
||||
|
||||
@post("/db/<pth:path>")
|
||||
def database_post(pth):
|
||||
|
Loading…
Reference in New Issue
Block a user