Async I/O implemented

This commit is contained in:
2023-06-22 13:16:12 +02:00
parent db77f62459
commit 47435c6128
3 changed files with 28 additions and 17 deletions

View File

@@ -1,3 +1,4 @@
import aiofiles
from os import path
from modules.app import app
from fastapi.responses import HTMLResponse, Response
@@ -5,27 +6,35 @@ from fastapi.responses import HTMLResponse, Response
@app.get("/pages/matter.css", include_in_schema=False)
async def page_matter():
with open(path.join("pages", "matter.css"), "r", encoding="utf-8") as f:
output = f.read()
async with aiofiles.open(
path.join("pages", "matter.css"), "r", encoding="utf-8"
) as f:
output = await f.read()
return Response(content=output)
@app.get("/pages/{page}/{file}", include_in_schema=False)
async def page_assets(page: str, file: str):
with open(path.join("pages", page, file), "r", encoding="utf-8") as f:
output = f.read()
async with aiofiles.open(
path.join("pages", page, file), "r", encoding="utf-8"
) as f:
output = await f.read()
return Response(content=output)
@app.get("/", include_in_schema=False)
async def page_home():
with open(path.join("pages", "home", "index.html"), "r", encoding="utf-8") as f:
output = f.read()
async with aiofiles.open(
path.join("pages", "home", "index.html"), "r", encoding="utf-8"
) as f:
output = await f.read()
return HTMLResponse(content=output)
@app.get("/register", include_in_schema=False)
async def page_register():
with open(path.join("pages", "register", "index.html"), "r", encoding="utf-8") as f:
output = f.read()
async with aiofiles.open(
path.join("pages", "register", "index.html"), "r", encoding="utf-8"
) as f:
output = await f.read()
return HTMLResponse(content=output)