Skip to content

Commit

Permalink
fix fonts bug with .css redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
anish-work committed Aug 1, 2024
1 parent a353d3d commit f5dcfb4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
53 changes: 27 additions & 26 deletions routers/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,20 +589,13 @@ def chat_lib_route(request: Request, integration_id: str, integration_name: str
)


# catch home page - TODO uncomment when home page is ready
# @gui.route(app, "/")
# def home_page(request: Request):
# import static_pages

# static_content = static_pages.serve("index", None)

# if static_content.get("redirectUrl"):
# return RedirectResponse(static_content.get("redirectUrl"))

# if static_content.get("content"):
# return Response(
# content=static_content["content"],
# )
@gui.route(app, "/")
def home_page(request: Request):
static_content = render_static_content(request, "index", None)
if static_content:
return static_content
else:
return HTTPException(status_code=404)


@gui.route(
Expand All @@ -622,23 +615,31 @@ def recipe_page_or_handle(
try:
handle = Handle.objects.get_by_name(page_slug)
except Handle.DoesNotExist:
import static_pages

static_content = static_pages.serve(page_slug, path)
if not static_content:
static_content = render_static_content(request, page_slug, path)
if static_content:
return static_content
else:
# render recipe page
return render_page(request, page_slug, RecipeTabs.run, example_id)
else:
return render_page_for_handle(request, handle)

if static_content.get("redirectUrl"):
return RedirectResponse(static_content.get("redirectUrl"))

if static_content.get("content"):
return Response(
content=static_content["content"],
)
def render_static_content(request: Request, page_slug: str, path: str | None):
import static_pages

else:
return render_page_for_handle(request, handle)
static_data = static_pages.serve(page_slug, path)
if not static_data:
# render recipe page
return

if static_data.get("redirectUrl"):
return RedirectResponse(static_data.get("redirectUrl"))

if static_data.get("content"):
return Response(
content=static_data["content"],
)


def render_page_for_handle(request: Request, handle: Handle):
Expand Down
10 changes: 5 additions & 5 deletions static_pages.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import django.urls
import gooey_gui as gui
from daras_ai_v2 import settings
import io
Expand Down Expand Up @@ -29,16 +28,17 @@ def serve(page_slug: str, file_path: str):

blob_path = ""
if page_slug and not file_path:
# If page_slug is provided, then it's a page
# If only page_slug is provided, then it's a page
blob_path = f"{WEBSITE_FOLDER_PATH}/{page_slug}.html"
elif file_path:
# fetch every file from root
blob_path = f"{WEBSITE_FOLDER_PATH}/{extract_file_name(file_path)}"

if not (blob_path.endswith(".html")):
# check .css cause fonts don't work in redirect
if not (blob_path.endswith(".html") or blob_path.endswith(".css")):
blob = bucket.get_blob(blob_path)
if not blob or not blob.exists():
return None # 404
return None # don't send 404 here, let the next handler handle it
# redirect every path that doesn't end with .html
return dict(
redirectUrl=f"https://storage.googleapis.com/{settings.GS_BUCKET_NAME}/{blob_path}"
Expand Down Expand Up @@ -80,7 +80,7 @@ def extract_zip_to_gcloud(self):
file_data = z.read(file_info)
file_name = extract_file_name(
file_info.filename
) # tp put everything at root
) # put everything at root
blob_path = f"{WEBSITE_FOLDER_PATH}/{file_name}"
blob = bucket.blob(blob_path)
content_type = (
Expand Down

0 comments on commit f5dcfb4

Please sign in to comment.