Organized PYHP files

This commit is contained in:
Krateng 2020-05-13 22:57:55 +02:00
parent afe01c8341
commit 1a64641fe6
20 changed files with 153 additions and 4 deletions

View File

@ -27,7 +27,7 @@ TRACK_SEARCH_PROVIDER = None
DB_CACHE_SIZE = 8192 # how many MB on disk each database cache should have available.
INVALID_ARTISTS = ["[Unknown Artist]","Unknown Artist","Spotify"]
REMOVE_FROM_TITLE = ["(Original Mix)","(Radio Edit)","(Album Version)","(Explicit Version)"]
REMOVE_FROM_TITLE = ["(Original Mix)","(Radio Edit)","(Album Version)","(Explicit Version)","(Bonus Track)"]
USE_PARSE_PLUGINS = no
[Local Images]
@ -61,6 +61,7 @@ NAME = None
EXPERIMENTAL_FEATURES = no
USE_PYHP = no #not recommended at the moment
USE_JINJA = no #overwrites pyhp preference
FEDERATION = yes #does nothing yet
UPDATE_AFTER_CRASH = no #update when server is automatically restarted
DAILY_RESTART = 2 # hour of day. no / none means no daily restarts

View File

@ -32,6 +32,7 @@ import signal
import os
import setproctitle
import pkg_resources
import math
# url handling
import urllib
@ -170,22 +171,75 @@ def static(name,ext):
return response
engine_prio = settings.get_settings("WEB_ENGINE_PRIORITY")
engines = {
"python":{"filetypes":["html","py"],"folder":"python"},
"pyhp":{"filetypes":["pyhp"],"folder":"pyhp"},
"jinja":{"filetypes":[],"folder":"jinja"}
}
JINJA_CONTEXT = {
# maloja
"db": database,
"htmlmodules": htmlmodules,
"htmlgenerators": htmlgenerators,
"malojatime": malojatime,
"utilities": utilities,
"urihandler": urihandler,
"settings": settings.get_settings,
# external
"urllib": urllib,
"math":math,
# config
"ranges": [
('day','7 days',malojatime.today().next(-6),'day',7),
('week','12 weeks',malojatime.thisweek().next(-11),'week',12),
('month','12 months',malojatime.thismonth().next(-11),'month',12),
('year','10 years',malojatime.thisyear().next(-9),'year',12)
]
}
from jinja2 import Environment, PackageLoader, select_autoescape
jinjaenv = Environment(
loader=PackageLoader('maloja', 'web/jinja'),
autoescape=select_autoescape(['html', 'xml'])
)
@webserver.route("/<name>")
def static_html(name):
linkheaders = ["</style.css>; rel=preload; as=style"]
keys = remove_identical(FormsDict.decode(request.query))
pyhp_file = os.path.exists(pthjoin(WEBFOLDER,name + ".pyhp"))
pyhp_file = os.path.exists(pthjoin(WEBFOLDER,"pyhp",name + ".pyhp"))
html_file = os.path.exists(pthjoin(WEBFOLDER,name + ".html"))
jinja_file = os.path.exists(pthjoin(WEBFOLDER,"jinja",name + ".jinja"))
pyhp_pref = settings.get_settings("USE_PYHP")
jinja_pref = settings.get_settings("USE_JINJA")
adminmode = request.cookies.get("adminmode") == "true" and database.checkAPIkey(request.cookies.get("apikey")) is not False
clock = Clock()
clock.start()
# if a jinja file exists, use this
if (jinja_file and jinja_pref) or (jinja_file and not html_file and not pyhp_file):
LOCAL_CONTEXT = {
"adminmode":adminmode,
"apikey":request.cookies.get("apikey") if adminmode else None,
"_urikeys":keys #temporary!
}
LOCAL_CONTEXT["filterkeys"], LOCAL_CONTEXT["limitkeys"], LOCAL_CONTEXT["delimitkeys"], LOCAL_CONTEXT["amountkeys"] = uri_to_internal(keys)
template = jinjaenv.get_template(name + '.jinja')
res = template.render(**JINJA_CONTEXT,**LOCAL_CONTEXT)
log("Generated page {name} in {time}s (Jinja)".format(name=name,time=clock.stop()),module="debug")
return res
# if a pyhp file exists, use this
if (pyhp_file and pyhp_pref) or (pyhp_file and not html_file):
elif (pyhp_file and pyhp_pref) or (pyhp_file and not html_file):
#things we expose to the pyhp pages
environ = {
@ -207,7 +261,7 @@ def static_html(name):
environ["_urikeys"] = keys #temporary!
#response.set_header("Content-Type","application/xhtml+xml")
res = pyhpfile(pthjoin(WEBFOLDER,name + ".pyhp"),environ)
res = pyhpfile(pthjoin(WEBFOLDER,"pyhp",name + ".pyhp"),environ)
log("Generated page {name} in {time}s (PYHP)".format(name=name,time=clock.stop()),module="debug")
return res

View File

@ -0,0 +1,56 @@
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}{% endblock %}</title>
<meta charset="UTF-8" />
<meta name="description" content='Maloja is a self-hosted music scrobble server.' />
<link rel="stylesheet" href="/style.css" />
<script src="/search.js"></script>
<script src="/neopolitan.js"></script>
<script src="/upload.js"></script>
{% block scripts %}{% endblock %}
</head>
<body>
{% block content %}
{% endblock %}
<div class="footer">
<div>
<span>Get your own Maloja scrobble server on <a target="_blank" rel="noopener noreferrer" href="https://github.com/krateng/maloja">GitHub</a></span>
</div>
<div>
<a href="/"><span style="font-weight:bold;">Maloja</span></a>
</div>
<div>
<span><input id="searchinput" placeholder="Search for an artist or track..." oninput="search(this)" onblur="clearresults()" /></span>
</div>
<span id="resultwrap" class="hide">
<div class="searchresults">
<span>Artists</span>
<table class="searchresults_artists" id="searchresults_artists">
</table>
<br/><br/>
<span>Tracks</span>
<table class="searchresults_tracks" id="searchresults_tracks">
</table>
</div>
</span>
</div>
<a href="/admin"><div title="Server Administration" id="settingsicon">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M17 12.645v-2.289c-1.17-.417-1.907-.533-2.28-1.431-.373-.9.07-1.512.6-2.625l-1.618-1.619c-1.105.525-1.723.974-2.626.6-.9-.374-1.017-1.117-1.431-2.281h-2.29c-.412 1.158-.53 1.907-1.431 2.28h-.001c-.9.374-1.51-.07-2.625-.6l-1.617 1.619c.527 1.11.973 1.724.6 2.625-.375.901-1.123 1.019-2.281 1.431v2.289c1.155.412 1.907.531 2.28 1.431.376.908-.081 1.534-.6 2.625l1.618 1.619c1.107-.525 1.724-.974 2.625-.6h.001c.9.373 1.018 1.118 1.431 2.28h2.289c.412-1.158.53-1.905 1.437-2.282h.001c.894-.372 1.501.071 2.619.602l1.618-1.619c-.525-1.107-.974-1.723-.601-2.625.374-.899 1.126-1.019 2.282-1.43zm-8.5 1.689c-1.564 0-2.833-1.269-2.833-2.834s1.269-2.834 2.833-2.834 2.833 1.269 2.833 2.834-1.269 2.834-2.833 2.834zm15.5 4.205v-1.077c-.55-.196-.897-.251-1.073-.673-.176-.424.033-.711.282-1.236l-.762-.762c-.52.248-.811.458-1.235.283-.424-.175-.479-.525-.674-1.073h-1.076c-.194.545-.25.897-.674 1.073-.424.176-.711-.033-1.235-.283l-.762.762c.248.523.458.812.282 1.236-.176.424-.528.479-1.073.673v1.077c.544.193.897.25 1.073.673.177.427-.038.722-.282 1.236l.762.762c.521-.248.812-.458 1.235-.283.424.175.479.526.674 1.073h1.076c.194-.545.25-.897.676-1.074h.001c.421-.175.706.034 1.232.284l.762-.762c-.247-.521-.458-.812-.282-1.235s.529-.481 1.073-.674zm-4 .794c-.736 0-1.333-.597-1.333-1.333s.597-1.333 1.333-1.333 1.333.597 1.333 1.333-.597 1.333-1.333 1.333z"/></svg>
</div></a>
</body>
</html>

View File

@ -0,0 +1,27 @@
<div class="footer">
<div>
<span>Get your own Maloja scrobble server on <a target="_blank" rel="noopener noreferrer" href="https://github.com/krateng/maloja">GitHub</a></span>
</div>
<div>
<a href="/"><span style="font-weight:bold;">Maloja</span></a>
</div>
<div>
<span><input id="searchinput" placeholder="Search for an artist or track..." oninput="search(this)" onblur="clearresults()" /></span>
</div>
<span id="resultwrap" class="hide">
<div class="searchresults">
<span>Artists</span>
<table class="searchresults_artists" id="searchresults_artists">
</table>
<br/><br/>
<span>Tracks</span>
<table class="searchresults_tracks" id="searchresults_tracks">
</table>
</div>
</span>
</div>
<a href="/admin"><div title="Server Administration" id="settingsicon">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M17 12.645v-2.289c-1.17-.417-1.907-.533-2.28-1.431-.373-.9.07-1.512.6-2.625l-1.618-1.619c-1.105.525-1.723.974-2.626.6-.9-.374-1.017-1.117-1.431-2.281h-2.29c-.412 1.158-.53 1.907-1.431 2.28h-.001c-.9.374-1.51-.07-2.625-.6l-1.617 1.619c.527 1.11.973 1.724.6 2.625-.375.901-1.123 1.019-2.281 1.431v2.289c1.155.412 1.907.531 2.28 1.431.376.908-.081 1.534-.6 2.625l1.618 1.619c1.107-.525 1.724-.974 2.625-.6h.001c.9.373 1.018 1.118 1.431 2.28h2.289c.412-1.158.53-1.905 1.437-2.282h.001c.894-.372 1.501.071 2.619.602l1.618-1.619c-.525-1.107-.974-1.723-.601-2.625.374-.899 1.126-1.019 2.282-1.43zm-8.5 1.689c-1.564 0-2.833-1.269-2.833-2.834s1.269-2.834 2.833-2.834 2.833 1.269 2.833 2.834-1.269 2.834-2.833 2.834zm15.5 4.205v-1.077c-.55-.196-.897-.251-1.073-.673-.176-.424.033-.711.282-1.236l-.762-.762c-.52.248-.811.458-1.235.283-.424-.175-.479-.525-.674-1.073h-1.076c-.194.545-.25.897-.674 1.073-.424.176-.711-.033-1.235-.283l-.762.762c.248.523.458.812.282 1.236-.176.424-.528.479-1.073.673v1.077c.544.193.897.25 1.073.673.177.427-.038.722-.282 1.236l.762.762c.521-.248.812-.458 1.235-.283.424.175.479.526.674 1.073h1.076c.194-.545.25-.897.676-1.074h.001c.421-.175.706.034 1.232.284l.762-.762c-.247-.521-.458-.812-.282-1.235s.529-.481 1.073-.674zm-4 .794c-.736 0-1.333-.597-1.333-1.333s.597-1.333 1.333-1.333 1.333.597 1.333 1.333-.597 1.333-1.333 1.333z"/></svg>
</div></a>

View File

@ -0,0 +1,11 @@
<meta name="description" content='Maloja is a self-hosted music scrobble server.' />
<!--<link rel="stylesheet/less" href="/less/maloja.less" />
<link rel="stylesheet/less" href="/less/grisons.less" />
<link rel="stylesheet" href="/css/maloja.css" />
<link rel="stylesheet" href="/css/grisons.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/less.js/3.9.0/less.min.js" ></script> -->
<link rel="stylesheet" href="/style.css" />
<script src="/search.js"></script>
<script src="/neopolitan.js"></script>
<script src="/upload.js"></script>