From f22f71d1e28d7f59fffbe0d24a4639e2b806b15e Mon Sep 17 00:00:00 2001 From: th3root Date: Sat, 11 Mar 2023 19:45:06 -0500 Subject: [PATCH] Working on a custom filter for base64 encoded image data. --- src/frontend/lib/FastAPIServer.py | 5 ++++- src/frontend/templates/index.html | 13 +++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/frontend/lib/FastAPIServer.py b/src/frontend/lib/FastAPIServer.py index 04cc637..e28ebcf 100644 --- a/src/frontend/lib/FastAPIServer.py +++ b/src/frontend/lib/FastAPIServer.py @@ -2,6 +2,7 @@ import uvicorn import os import sass +import base64 from fastapi import FastAPI, Request from fastapi.responses import HTMLResponse from fastapi.routing import APIRoute @@ -13,7 +14,9 @@ from ...backend.lib.config import Config app = FastAPI() templates = Jinja2Templates(directory="src/frontend/templates") - +def base64decode(string): + return base64.b64decode(string).decode("utf-8") +templates.env.filters["b64decode"] = base64decode class FastAPIServer(): """Entry point for FastAPI server.""" diff --git a/src/frontend/templates/index.html b/src/frontend/templates/index.html index 6ef7abc..619768f 100644 --- a/src/frontend/templates/index.html +++ b/src/frontend/templates/index.html @@ -7,14 +7,22 @@
- {{ book[0].title }} + {% try %} + {{ book[0].title }} + {% except %} + Placeholder image + {% endtry %}
- Placeholder image + {% try %} + Placeholder image + {% except %} + Placeholder image + {% endtry %}
@@ -28,6 +36,7 @@
+
{% endfor %}