PhotosAPI/extensions/pages.py

37 lines
1.1 KiB
Python
Raw Normal View History

2023-06-23 11:51:42 +03:00
from pathlib import Path
2023-06-22 14:17:53 +03:00
import aiofiles
2022-12-20 16:34:47 +02:00
from fastapi.responses import HTMLResponse, Response
2023-06-22 14:17:53 +03:00
from modules.app import app
2023-03-12 15:59:13 +02:00
2022-12-20 16:34:47 +02:00
@app.get("/pages/matter.css", include_in_schema=False)
async def page_matter():
2023-06-23 11:51:42 +03:00
async with aiofiles.open(Path("pages/matter.css"), "r", encoding="utf-8") as f:
2023-06-22 14:16:12 +03:00
output = await f.read()
2022-12-20 16:34:47 +02:00
return Response(content=output)
2023-03-12 15:59:13 +02:00
2022-12-20 16:34:47 +02:00
@app.get("/pages/{page}/{file}", include_in_schema=False)
2023-03-12 15:59:13 +02:00
async def page_assets(page: str, file: str):
2023-06-23 11:51:42 +03:00
async with aiofiles.open(Path(f"pages/{page}/{file}"), "r", encoding="utf-8") as f:
2023-06-22 14:16:12 +03:00
output = await f.read()
2022-12-20 16:34:47 +02:00
return Response(content=output)
2023-03-12 15:59:13 +02:00
2022-12-20 16:34:47 +02:00
@app.get("/", include_in_schema=False)
async def page_home():
2023-06-23 11:51:42 +03:00
async with aiofiles.open(Path("pages/home/index.html"), "r", encoding="utf-8") as f:
2023-06-22 14:16:12 +03:00
output = await f.read()
2022-12-20 16:34:47 +02:00
return HTMLResponse(content=output)
2023-03-12 15:59:13 +02:00
2022-12-20 16:34:47 +02:00
@app.get("/register", include_in_schema=False)
async def page_register():
2023-06-22 14:16:12 +03:00
async with aiofiles.open(
2023-06-23 11:51:42 +03:00
Path("pages/register/index.html"), "r", encoding="utf-8"
2023-06-22 14:16:12 +03:00
) as f:
output = await f.read()
2023-03-12 15:59:13 +02:00
return HTMLResponse(content=output)