mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Finished b64 image filter
This commit is contained in:
19
src/frontend/lib/FastAPIServer.py
vendored
19
src/frontend/lib/FastAPIServer.py
vendored
@@ -2,7 +2,7 @@
|
|||||||
import uvicorn
|
import uvicorn
|
||||||
import os
|
import os
|
||||||
import sass
|
import sass
|
||||||
import base64
|
from base64 import b64encode
|
||||||
from fastapi import FastAPI, Request
|
from fastapi import FastAPI, Request
|
||||||
from fastapi.responses import HTMLResponse
|
from fastapi.responses import HTMLResponse
|
||||||
from fastapi.routing import APIRoute
|
from fastapi.routing import APIRoute
|
||||||
@@ -14,10 +14,21 @@ from ...backend.lib.config import Config
|
|||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
templates = Jinja2Templates(directory="src/frontend/templates")
|
templates = Jinja2Templates(directory="src/frontend/templates")
|
||||||
def base64decode(string):
|
|
||||||
return base64.b64decode(string).decode("utf-8")
|
|
||||||
|
def base64decode(string) -> str:
|
||||||
|
"""Decode a base64 string."""
|
||||||
|
breakpoint()
|
||||||
|
try:
|
||||||
|
result = b64encode(string).decode("utf-8")
|
||||||
|
except Exception:
|
||||||
|
result = "static/images/placeholder.png"
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
templates.env.filters["b64decode"] = base64decode
|
templates.env.filters["b64decode"] = base64decode
|
||||||
|
|
||||||
|
|
||||||
class FastAPIServer():
|
class FastAPIServer():
|
||||||
"""Entry point for FastAPI server."""
|
"""Entry point for FastAPI server."""
|
||||||
|
|
||||||
@@ -58,7 +69,7 @@ class FastAPIServer():
|
|||||||
"""Home page responder."""
|
"""Home page responder."""
|
||||||
# _books = self.storage.get_books()
|
# _books = self.storage.get_books()
|
||||||
context = {"request": request, "books": books}
|
context = {"request": request, "books": books}
|
||||||
return templates.TemplateResponse("index.html", context )
|
return templates.TemplateResponse("index.html", context)
|
||||||
|
|
||||||
@app.get("/users/me")
|
@app.get("/users/me")
|
||||||
async def about_me(self):
|
async def about_me(self):
|
||||||
|
|||||||
@@ -7,22 +7,14 @@
|
|||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-image">
|
<div class="card-image">
|
||||||
<figure class="image is-4by3">
|
<figure class="image is-4by3">
|
||||||
{% try %}
|
<img src="data:;base64,{{ book[0].cover|b64decode }}" alt="{{ book[0].title }}">
|
||||||
<img src="data:image/png;base64,{{ book[0].cover|b64decode }}" alt="{{ book[0].title }}">
|
|
||||||
{% except %}
|
|
||||||
<img src="https://bulma.io/images/placeholders/1280x960.png" alt="Placeholder image">
|
|
||||||
{% endtry %}
|
|
||||||
</figure>
|
</figure>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
<div class="media">
|
<div class="media">
|
||||||
<div class="media-left">
|
<div class="media-left">
|
||||||
<figure class="image is-48x48">
|
<figure class="image is-48x48">
|
||||||
{% try %}
|
<img src="data:;base64,{{ book[0].cover|b64decode }}" alt="Placeholder image">
|
||||||
<img src="data:image/png;base64,{{ book[0].cover|b64decode }}" alt="Placeholder image">
|
|
||||||
{% except %}
|
|
||||||
<img src="https://bulma.io/images/placeholders/96x96.png" alt="Placeholder image">
|
|
||||||
{% endtry %}
|
|
||||||
</figure>
|
</figure>
|
||||||
</div>
|
</div>
|
||||||
<div class="media-content">
|
<div class="media-content">
|
||||||
|
|||||||
Reference in New Issue
Block a user