making async api - 2

This commit is contained in:
2023-08-31 23:41:48 +03:00
parent 4326c70dbc
commit 2c870ee983
4 changed files with 27 additions and 14 deletions

View File

@ -11,6 +11,7 @@ from typing import Any, Annotated, List, Union
from starlette.staticfiles import StaticFiles
from sqlalchemy.orm import Session
from sqlalchemy import select
from dotenv import load_dotenv, dotenv_values
import requests
from uuid import uuid4
@ -41,6 +42,14 @@ if not os.path.exists("./uploads"):
# создаем эндпоинт для хранения файлов пользователя
app.mount("/uploads", StaticFiles(directory = "./uploads"))
# load_dotenv("unimportant.env")
# ACCESS_TOKEN_EXPIRE_MINUTES = os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES")
ACCESS_TOKEN_EXPIRE_MINUTES = 1440
# эндпоинт для возвращения согласия в pdf
@app.get("/privacy_policy.pdf")
async def privacy_policy():
return FileResponse("privacy_policy.pdf")
# получение списка объявлений
@app.get("/api/announcements", response_model=List[pydantic_schemas.Announcement])#адрес объявлений
@ -176,7 +185,7 @@ async def login_for_access_token(
headers={"WWW-Authenticate": "Bearer"},
)
# задаем временной интервал, в течение которого токен можно использовать
access_token_expires = await auth_utils.timedelta(minutes=auth_utils.ACCESS_TOKEN_EXPIRE_MINUTES)
access_token_expires = auth_utils.timedelta(minutes=auth_utils.ACCESS_TOKEN_EXPIRE_MINUTES)
# создаем токен
access_token = await auth_utils.create_access_token(
data={"user_id": user.id}, expires_delta=access_token_expires
@ -289,7 +298,7 @@ async def get_trashboxes(data: pydantic_schemas.TrashboxRequest = Depends()):#к
@app.get("/{rest_of_path:path}")
async def react_app(req: Request, rest_of_path: str):
await templates.TemplateResponse('index.html', { 'request': req })
return templates.TemplateResponse('index.html', { 'request': req })
@app.post("/api/announcement/dispose")