-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
24 lines (17 loc) · 823 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from fastapi import FastAPI, Form, Request
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from insert_file import query_file
app = FastAPI()
templates = Jinja2Templates(directory="pages")
app.mount("/static", StaticFiles(directory="pages/static"), name="static")
@app.get("/", response_class=HTMLResponse)
async def intial(request: Request):
return templates.TemplateResponse("home.html", {"request": request})
@app.post("/auth", response_class=HTMLResponse)
async def form(request: Request, hash_code: str = Form()):
content = query_file(hash_code)
with open("pages/static/file_1.pdf", "wb") as file:
file.write(content.file_content)
return templates.TemplateResponse("index.html", {"request": request})