summaryrefslogtreecommitdiff
path: root/app/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/main.py')
-rw-r--r--app/main.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/app/main.py b/app/main.py
index d9ea01c..891adb1 100644
--- a/app/main.py
+++ b/app/main.py
@@ -1,11 +1,27 @@
+from pathlib import Path
+
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
+from fastapi.staticfiles import StaticFiles
from starlette.templating import Jinja2Templates
import httpx
+templates = Jinja2Templates(directory="templates")
+
app = FastAPI()
+app.mount("/static", StaticFiles(directory="static"), name="static")
-templates = Jinja2Templates(directory="templates")
+
+def get_avatar_urls():
+ path = Path('./static') / 'avatars'
+ if not path.exists():
+ path.mkdir()
+
+ return sorted([
+ str(jpg_avatar)
+ for jpg_avatar
+ in path.glob('*.jpg')
+ ])
def get_client_host(request: Request):
@@ -31,6 +47,7 @@ async def index(request: Request):
"request": request,
"client_geo": await get_client_geo(
get_client_host(request)
- )
+ ),
+ "avatar_urls": get_avatar_urls()
}
)