Merge pull request #237 from arabcoders/dev

Nested browser frontend page was not loading correctly.
This commit is contained in:
Abdulmohsen 2025-03-28 02:27:31 +03:00 committed by GitHub
commit 5bac7b8d20
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -67,6 +67,17 @@ class HttpAPI(Common):
}
"""Map ext to mimetype"""
_frontend_routes = [
"/console",
"/presets",
"/tasks",
"/notifications",
"/changeslog",
"/browser",
"/browser/{path:.*}",
]
"""Frontend routes to be preloaded"""
def __init__(
self,
queue: DownloadQueue | None = None,
@ -159,10 +170,17 @@ class HttpAPI(Common):
"""
path = req.path
if req.path not in self._static_holder:
return web.json_response({"error": "File not found.", "file": path}, status=web.HTTPNotFound.status_code)
if path not in self._static_holder:
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(
body=item.get("content"),
@ -212,12 +230,12 @@ class HttpAPI(Common):
preloaded += 1
if urlPath.endswith("/index.html"):
paths_list = ["/console", "/presets", "/tasks", "/notifications", "/changeslog", "/browser"]
for path in paths_list:
for path in self._frontend_routes:
self._static_holder[path] = {"content": content, "content_type": contentType}
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)
if "{" not in path:
self._static_holder[path + "/"] = {"content": content, "content_type": contentType}
app.router.add_get(path + "/", self._static_file)
LOG.debug(f"Preloading '{path}'.")
preloaded += 1