mirror of
https://github.com/fHDHR/fHDHR_NextPVR.git
synced 2025-12-06 06:36:58 -05:00
Allow Cross Origin CSS Theming via cache
This commit is contained in:
parent
4fa82037b8
commit
8661c77089
@ -6,9 +6,6 @@
|
||||
table, th, td {border: 1px solid black;}
|
||||
</style>
|
||||
<link href="style.css" rel="stylesheet">
|
||||
{% if fhdhr.config.dict["web_ui"]["theme"] %}
|
||||
<link href={{ fhdhr.config.dict["web_ui"]["theme"] }} rel="stylesheet">
|
||||
{% endif %}
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="text-align: center;">
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from gevent.pywsgi import WSGIServer
|
||||
from flask import Flask
|
||||
from flask import Flask, request
|
||||
|
||||
from .pages import fHDHR_Pages
|
||||
from .files import fHDHR_Files
|
||||
@ -35,6 +35,16 @@ class fHDHR_HTTP_Server():
|
||||
self.watch = fHDHR_WATCH(fhdhr)
|
||||
self.add_endpoints(self.watch, "watch")
|
||||
|
||||
self.app.before_request(self.before_request)
|
||||
self.app.after_request(self.after_request)
|
||||
|
||||
def before_request(self):
|
||||
self.fhdhr.logger.debug("")
|
||||
|
||||
def after_request(self, response):
|
||||
self.fhdhr.logger.debug("")
|
||||
return response
|
||||
|
||||
def add_endpoints(self, index_list, index_name):
|
||||
item_list = [x for x in dir(index_list) if self.isapath(x)]
|
||||
for item in item_list:
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
from flask import send_from_directory
|
||||
from flask import Response
|
||||
import pathlib
|
||||
from io import StringIO
|
||||
|
||||
|
||||
class Style_CSS():
|
||||
@ -8,10 +10,35 @@ class Style_CSS():
|
||||
def __init__(self, fhdhr):
|
||||
self.fhdhr = fhdhr
|
||||
|
||||
self.internal_style_file = pathlib.Path(
|
||||
self.fhdhr.config.internal["paths"]["www_dir"]).joinpath('style.css')
|
||||
|
||||
self.internal_style = StringIO()
|
||||
self.internal_style.write(open(self.internal_style_file).read())
|
||||
|
||||
self.pull_external_theme()
|
||||
|
||||
def pull_external_theme(self):
|
||||
self.external_style = None
|
||||
self.external_style_address = None
|
||||
if self.fhdhr.config.dict["web_ui"]["theme"]:
|
||||
if self.fhdhr.config.dict["web_ui"]["theme"].startswith(tuple(["http://", "https://"])):
|
||||
css_req = self.fhdhr.web.session.get(self.fhdhr.config.dict["web_ui"]["theme"])
|
||||
self.external_style = StringIO(css_req.text)
|
||||
self.external_style_address = self.fhdhr.config.dict["web_ui"]["theme"]
|
||||
|
||||
def __call__(self, *args):
|
||||
return self.get(*args)
|
||||
|
||||
def get(self, *args):
|
||||
|
||||
return send_from_directory(self.fhdhr.config.internal["paths"]["www_dir"],
|
||||
'style.css')
|
||||
main_output = StringIO()
|
||||
|
||||
main_output.write(self.internal_style.getvalue())
|
||||
if self.fhdhr.config.dict["web_ui"]["theme"]:
|
||||
if self.fhdhr.config.dict["web_ui"]["theme"] != self.external_style_address:
|
||||
self.pull_external_theme()
|
||||
if self.external_style:
|
||||
main_output.write(self.external_style.getvalue())
|
||||
|
||||
return Response(status=200, response=main_output.getvalue(), mimetype="text/css")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user