1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Added versioning and admin panel

This commit is contained in:
Krateng 2019-11-19 20:52:07 +01:00
parent 36754ade85
commit a61208a2f8
7 changed files with 107 additions and 1 deletions

View File

@ -230,6 +230,17 @@ def test_server(key=None):
# 205 Database server is up, but DB is not fully built or is inconsistent
# 403 Database server is up, but provided API key is not valid
@dbserver.get("serverinfo")
def server_info():
import info
response.set_header("Access-Control-Allow-Origin","*")
response.set_header("Content-Type","application/json")
return {
"name":settings.get_settings("NAME"),
"version":info.version
}
## All database functions are separated - the external wrapper only reads the request keys, converts them into lists and renames them where necessary, and puts the end result in a dict if not already so it can be returned as json

1
info.py Normal file
View File

@ -0,0 +1 @@
version = 1,5,10

View File

@ -14,6 +14,7 @@ import utilities
from utilities import resolveImage
from urihandler import uri_to_internal, remove_identical
import urihandler
import info
# doreah toolkit
from doreah import settings
from doreah.logging import log
@ -160,6 +161,7 @@ def static_html(name):
environ["malojatime"] = malojatime
environ["utilities"] = utilities
environ["urihandler"] = urihandler
environ["info"] = info
# external
environ["urllib"] = urllib
# request

View File

@ -56,4 +56,4 @@ NAME = "Generic Maloja User"
[Misc]
EXPERIMENTAL_FEATURES = no
USE_PYHP = no
USE_PYHP = yes

63
website/admin.pyhp Normal file
View File

@ -0,0 +1,63 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Maloja</title>
<script src="javascript/cookies.js"></script>
<pyhp include="common/header.html" />
<script>
neo.xhttprequest("https://maloja.krateng.ch/api/serverinfo",{},"GET",json=true).then((response)=>{
result = JSON.parse(response.responseText);
document.getElementById("latestversion").innerHTML = result.version.join(".");
if (document.getElementById("latestversion").innerHTML.trim() == document.getElementById("currentversion").innerHTML.trim()) {
document.getElementById("currentversion").style.color = "green";
}
else {
document.getElementById("currentversion").style.color = "red";
document.getElementById("updatestatus").innerHTML = "Consider updating to take advantage of new features";
}
});
</script>
</head>
<body>
<table class="top_info">
<tr>
<td class="image">
<div style="background-image:url('/favicon.png')"></div>
</td>
<td class="text">
<h1>Maloja</h1><br/>
<p class="desc">Welcome to your own Maloja server!</p>
</td>
</tr>
</table>
<h2>Update</h2>
Currently installed Maloja version: <span id="currentversion"><pyhp echo="'.'.join(str(n) for n in info.version)" /></span><br/>
Latest Maloja version: <span id="latestversion">Loading...</span><br/>
<span id="updatestatus"></span>
<h2>Admin Mode</h2>
Activate admin mode to manually scrobble from various places on the website
<h2>Links</h2>
<a class="textlink" href="/setup">Server Setup</a><br/>
<a class="textlink" href="/manual">Manual Scrobbling</a>
<pyhp include="common/footer.html" />
</body>
</html>

View File

@ -7,3 +7,4 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/less.js/3.9.0/less.min.js" ></script> -->
<link rel="stylesheet" href="/css/style.css" />
<script src="/javascript/search.js" async></script>
<script src="/javascript/neopolitan.js"></script>

View File

@ -0,0 +1,28 @@
var neo=function(){var cookies={};var cookiesloaded=false;function getCookies(){cookiestrings=decodeURIComponent(document.cookie).split(';');for(var i=0;i<cookiestrings.length;i++){cookiestrings[i]=cookiestrings[i].trim();[key,value]=cookiestrings[i].split("=");cookies[key]=value;}
cookiesloaded=true;}
document.addEventListener("load",getCookies);function setCookie(key,val,session=true){if(!cookiesloaded){getCookies();}
cookies[key]=val;if(!session){var d=new Date();d.setTime(d.getTime()+(500*24*60*60*1000));expirestr="expires="+d.toUTCString();}
else{expirestr=""}
document.cookie=encodeURIComponent(key)+'='+encodeURIComponent(val)+';'+expirestr;}
function getCookie(key){if(!cookiesloaded){getCookies();}
return cookies[key];}
function saveCookies(){for(var c in cookies){document.cookie=encodeURIComponent(c)+'='+encodeURIComponent(cookies[c])*'';}}
function xhttpreq(url,data={},method="GET",callback=function(){},json=true){xhttp=new XMLHttpRequest();function curry(){if(this.readyState==4){callback(this);}}
xhttp.onreadystatechange=curry;xhttp.open(method,url,true);body=""
if(method=="GET"){url+="?";for(var key in data){url+=encodeURIComponent(key)+"="+encodeURIComponent(data[key])+"&";}}
else{if(json){body=JSON.stringify(data);xhttp.setRequestHeader("Content-Type","application/json");xhttp.responseType="json";}
else{for(var key in data){body+=encodeURIComponent(key)+"="+encodeURIComponent(data[key])+"&";}}}
xhttp.send(body);console.log("Sent XHTTP request to",url)}
function xhttprequest(url,data={},method="GET",json=true){var p=new Promise(resolve=>xhttpreq(url,data,method,resolve,json));return p;}
function now(){return Math.floor(Date.now()/1000);}
return{getCookie:getCookie,setCookie:setCookie,getCookies:getCookies,saveCookies:saveCookies,xhttpreq:xhttpreq,xhttprequest:xhttprequest,now:now}}();document.addEventListener('DOMContentLoaded',function(){var elements=document.getElementsByClassName("seekable");for(var i=0;i<elements.length;i++){callback=elements[i].getAttribute("data-seekcallback");elements[i].addEventListener("click",function(evt){elmnt=evt.currentTarget;var percentage=evt.offsetX/elmnt.offsetWidth;elmnt.firstElementChild.style.width=(percentage*100)+"%";window[callback](percentage);})}
var elements2=document.getElementsByClassName("update");var functions=[]
for(var i=0;i<elements2.length;i++){updatefunc=elements2[i].getAttribute("data-updatefrom");functions.push([elements2[i],updatefunc])}
const SMOOTH_UPDATE=true;const update_delay=SMOOTH_UPDATE?40:500;function supervisor(){for(let entry of functions){var[element,func]=entry
window[func](element);}
setTimeout(supervisor,update_delay);}
if(functions.length>0){supervisor();}
var body=document.getElementsByTagName("BODY")[0]
if(body.getAttribute("data-linkinterceptor")!=undefined){var interceptor=eval(body.getAttribute("data-linkinterceptor"));function interceptClickEvent(e){var href;var target=e.target||e.srcElement;if(target.tagName==='A'&&!target.classList.contains("no-intercept")){href=target.getAttribute('href');e.preventDefault();history.pushState({},"",href);interceptor();}}
document.addEventListener('click',interceptClickEvent);}},false);document.addEventListener('keyup',function(evt){if(evt.srcElement.tagName=="INPUT"){return;}
var elements=document.querySelectorAll('[data-hotkey]');for(let e of elements){if(e.getAttribute("data-hotkey")==evt.code){evt.preventDefault();e.onclick();break;}}},false);