Merge pull request #237 from arabcoders/dev
Nested browser frontend page was not loading correctly.
This commit is contained in:
commit
5bac7b8d20
1 changed files with 25 additions and 7 deletions
|
|
@ -67,6 +67,17 @@ class HttpAPI(Common):
|
||||||
}
|
}
|
||||||
"""Map ext to mimetype"""
|
"""Map ext to mimetype"""
|
||||||
|
|
||||||
|
_frontend_routes = [
|
||||||
|
"/console",
|
||||||
|
"/presets",
|
||||||
|
"/tasks",
|
||||||
|
"/notifications",
|
||||||
|
"/changeslog",
|
||||||
|
"/browser",
|
||||||
|
"/browser/{path:.*}",
|
||||||
|
]
|
||||||
|
"""Frontend routes to be preloaded"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
queue: DownloadQueue | None = None,
|
queue: DownloadQueue | None = None,
|
||||||
|
|
@ -159,10 +170,17 @@ class HttpAPI(Common):
|
||||||
"""
|
"""
|
||||||
path = req.path
|
path = req.path
|
||||||
|
|
||||||
if req.path not in self._static_holder:
|
if path not in self._static_holder:
|
||||||
return web.json_response({"error": "File not found.", "file": path}, status=web.HTTPNotFound.status_code)
|
for k in self._static_holder:
|
||||||
|
if path.startswith(k):
|
||||||
|
path = k
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
return web.json_response(
|
||||||
|
{"error": "File not found.", "file": path}, status=web.HTTPNotFound.status_code
|
||||||
|
)
|
||||||
|
|
||||||
item: dict = self._static_holder[req.path]
|
item: dict = self._static_holder[path]
|
||||||
|
|
||||||
return web.Response(
|
return web.Response(
|
||||||
body=item.get("content"),
|
body=item.get("content"),
|
||||||
|
|
@ -212,12 +230,12 @@ class HttpAPI(Common):
|
||||||
preloaded += 1
|
preloaded += 1
|
||||||
|
|
||||||
if urlPath.endswith("/index.html"):
|
if urlPath.endswith("/index.html"):
|
||||||
paths_list = ["/console", "/presets", "/tasks", "/notifications", "/changeslog", "/browser"]
|
for path in self._frontend_routes:
|
||||||
for path in paths_list:
|
|
||||||
self._static_holder[path] = {"content": content, "content_type": contentType}
|
self._static_holder[path] = {"content": content, "content_type": contentType}
|
||||||
app.router.add_get(path, self._static_file)
|
app.router.add_get(path, self._static_file)
|
||||||
self._static_holder[path + "/"] = {"content": content, "content_type": contentType}
|
if "{" not in path:
|
||||||
app.router.add_get(path + "/", self._static_file)
|
self._static_holder[path + "/"] = {"content": content, "content_type": contentType}
|
||||||
|
app.router.add_get(path + "/", self._static_file)
|
||||||
LOG.debug(f"Preloading '{path}'.")
|
LOG.debug(f"Preloading '{path}'.")
|
||||||
preloaded += 1
|
preloaded += 1
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue