Hash dashboard resources

This commit is contained in:
Otto Winter 2018-12-24 14:29:11 +01:00
parent 5a7b66e207
commit 6aac4191f8
No known key found for this signature in database
GPG key ID: DB66C0BE6013F97E
3 changed files with 38 additions and 17 deletions

View file

@ -296,7 +296,8 @@ class MainRequestHandler(BaseHandler):
'https://esphomelib.com/esphomeyaml/' 'https://esphomelib.com/esphomeyaml/'
self.render("templates/index.html", entries=entries, self.render("templates/index.html", entries=entries,
version=version, begin=begin, docs_link=docs_link) version=version, begin=begin, docs_link=docs_link,
get_static_file_url=get_static_file_url)
def _ping_func(filename, address): def _ping_func(filename, address):
@ -413,7 +414,8 @@ class LoginHandler(BaseHandler):
docs_link = 'https://beta.esphomelib.com/esphomeyaml/' if 'b' in version else \ docs_link = 'https://beta.esphomelib.com/esphomeyaml/' if 'b' in version else \
'https://esphomelib.com/esphomeyaml/' 'https://esphomelib.com/esphomeyaml/'
self.render("templates/login.html", version=version, docs_link=docs_link, error=error) self.render("templates/login.html", version=version, docs_link=docs_link, error=error,
get_static_file_url=get_static_file_url)
def post_hassio_login(self): def post_hassio_login(self):
import requests import requests
@ -451,6 +453,21 @@ class LoginHandler(BaseHandler):
self.redirect("/") self.redirect("/")
_STATIC_FILE_HASHES = {}
def get_static_file_url(name):
static_path = os.path.join(os.path.dirname(__file__), 'static')
if name in _STATIC_FILE_HASHES:
hash_ = _STATIC_FILE_HASHES[name]
else:
path = os.path.join(static_path, name)
with open(path, 'rb') as f_handle:
hash_ = hash(f_handle.read())
_STATIC_FILE_HASHES[name] = hash_
return u'/static/{}?hash={}'.format(name, hash_)
def make_app(debug=False): def make_app(debug=False):
def log_function(handler): def log_function(handler):
if handler.get_status() < 400: if handler.get_status() < 400:
@ -493,6 +510,10 @@ def make_app(debug=False):
(r"/wizard.html", WizardRequestHandler), (r"/wizard.html", WizardRequestHandler),
(r'/static/(.*)', StaticFileHandler, {'path': static_path}), (r'/static/(.*)', StaticFileHandler, {'path': static_path}),
], debug=debug, cookie_secret=COOKIE_SECRET, log_function=log_function) ], debug=debug, cookie_secret=COOKIE_SECRET, log_function=log_function)
if debug:
_STATIC_FILE_HASHES.clear()
return app return app

View file

@ -4,17 +4,17 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>ESPHome Dashboard</title> <title>ESPHome Dashboard</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="/static/materialize.min.css?v=1"> <link rel="stylesheet" href="{{ get_static_file_url('materialize.min.css') }}">
<link rel="stylesheet" href="/static/materialize-stepper.min.css?v=1"> <link rel="stylesheet" href="{{ get_static_file_url('materialize-stepper.min.css') }}">
<link rel="stylesheet" href="/static/esphomeyaml.css?v=1"> <link rel="stylesheet" href="{{ get_static_file_url('esphomeyaml.css') }}">
<link rel="shortcut icon" href="/static/favicon.ico?v=1"> <link rel="shortcut icon" href="{{ get_static_file_url('favicon.ico') }}">
<script src="/static/jquery.min.js?v=1"></script> <script src="{{ get_static_file_url('jquery.min.js') }}"></script>
<script src="/static/jquery-ui.min.js?v=1"></script> <script src="{{ get_static_file_url('jquery-ui.min.js') }}"></script>
<script src="/static/materialize.min.js?v=1"></script> <script src="{{ get_static_file_url('materialize.min.js') }}"></script>
<script src="/static/jquery.validate.min.js?v=1"></script> <script src="{{ get_static_file_url('jquery.validate.min.js') }}"></script>
<script src="/static/materialize-stepper.min.js?v=1"></script> <script src="{{ get_static_file_url('materialize-stepper.min.js') }}"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head> </head>
<body> <body>
@ -469,8 +469,8 @@
</div> </div>
</footer> </footer>
<script src="/static/ace.js?v=1" type="text/javascript" charset="utf-8"></script> <script src="{{ get_static_file_url('ace.js') }}" type="text/javascript" charset="utf-8"></script>
<script src="/static/esphomeyaml.js?v=1" type="text/javascript"></script> <script src="{{ get_static_file_url('esphomeyaml.js') }}" type="text/javascript"></script>
{% if len(entries) == 0 %} {% if len(entries) == 0 %}
<script> <script>

View file

@ -4,11 +4,11 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>esphomeyaml Dashboard</title> <title>esphomeyaml Dashboard</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="/static/materialize.min.css?v=1"> <link rel="stylesheet" href="{{ get_static_file_url('materialize.min.css') }}">
<link rel="stylesheet" href="/static/esphomeyaml.css?v=1"> <link rel="stylesheet" href="{{ get_static_file_url('esphomeyaml.css') }}">
<link rel="shortcut icon" href="/static/favicon.ico?v=1"> <link rel="shortcut icon" href="{{ get_static_file_url('favicon.ico') }}">
<script src="/static/materialize.min.js?v=1"></script> <script src="{{ get_static_file_url('materialize.min.js') }}"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head> </head>