Move wrapper necessary check to separate function

This commit is contained in:
shortcutme 2020-05-03 03:56:06 +02:00
parent 3c7022ea9d
commit 07faa3d6d3
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
1 changed files with 17 additions and 8 deletions

View File

@ -334,6 +334,22 @@ class UiRequest(object):
return template_rendered.encode("utf8")
def isWrapperNecessary(self, path):
match = re.match(r"/(?P<address>[A-Za-z0-9\._-]+)(?P<inner_path>/.*|$)", path)
if not match:
return True
inner_path = match.group("inner_path").lstrip("/")
if not inner_path or path.endswith("/"): # It's a directory
content_type = self.getContentType("index.html")
else: # It's a file
content_type = self.getContentType(inner_path)
is_html_file = "html" in content_type or "xhtml" in content_type
return is_html_file
# - Actions -
# Redirect to an url
@ -356,14 +372,7 @@ class UiRequest(object):
address = match.group("address")
inner_path = match.group("inner_path").lstrip("/")
if not inner_path or path.endswith("/"): # It's a directory
content_type = self.getContentType("index.html")
else: # It's a file
content_type = self.getContentType(inner_path)
is_html_file = "html" in content_type or "xhtml" in content_type
if not is_html_file:
if not self.isWrapperNecessary(path):
return self.actionSiteMedia("/media" + path) # Serve non-html files without wrapper
if self.isAjaxRequest():