diff --git a/daras_ai_v2/static_pages.py b/daras_ai_v2/static_pages.py index 6cb5e7401..f7655fb02 100644 --- a/daras_ai_v2/static_pages.py +++ b/daras_ai_v2/static_pages.py @@ -1,4 +1,5 @@ import io +from starlette.responses import Response from static_pages.models import StaticPage from google.cloud import storage @@ -51,12 +52,17 @@ def get_all_styles(links: list, uid: str): return f"" -def serve(page_slug: str, file_path: str = None): +def serve(request: Response, page_slug: str): static_page = StaticPage.objects.get(path=page_slug) - if not static_page: return None + file_path = request.url.path + if not file_path == f"/{page_slug}/": + file_path = file_path[len(f"/{page_slug}/") :] + else: + file_path = None + uid = static_page.uid bucket = gcs_bucket() diff --git a/routers/root.py b/routers/root.py index a06168926..55070c822 100644 --- a/routers/root.py +++ b/routers/root.py @@ -578,15 +578,15 @@ def chat_lib_route(request: Request, integration_id: str, integration_name: str app, "/{page_slug}/", "/{page_slug}/{run_slug}/", + "/{page_slug}/{run_slug}/{path}", "/{page_slug}/{run_slug}-{example_id}/", - "/{page_slug}/{path:path}", ) def recipe_page_or_handle( request: Request, page_slug: str, run_slug: str = None, - example_id: str = None, path: str = None, + example_id: str = None, ): try: handle = Handle.objects.get_by_name(page_slug) @@ -594,7 +594,10 @@ def recipe_page_or_handle( try: import daras_ai_v2.static_pages as static_pages - html, file_path = static_pages.serve(page_slug=page_slug, file_path=path) + html, file_path = static_pages.serve( + request=request, + page_slug=page_slug, + ) if file_path: return RedirectResponse(file_path)