change async path functions from async so that fastapi handles concurrency for non-async apis
This commit is contained in:
@@ -99,12 +99,12 @@ def verify_auth_token(token: str):
|
|||||||
raise HTTPException(status_code=401, detail="invalid access token")
|
raise HTTPException(status_code=401, detail="invalid access token")
|
||||||
|
|
||||||
@app.post("/report")
|
@app.post("/report")
|
||||||
async def report_slop(report: SlopReport, bearer: Annotated[str, AfterValidator(verify_auth_token), Header()]):
|
def report_slop(report: SlopReport, bearer: Annotated[str, AfterValidator(verify_auth_token), Header()]):
|
||||||
user = get_token_user(bearer)
|
user = get_token_user(bearer)
|
||||||
insert_slop(report.slop_urls, DB_ENGINE, user)
|
insert_slop(report.slop_urls, DB_ENGINE, user)
|
||||||
|
|
||||||
@app.post("/check")
|
@app.post("/check")
|
||||||
async def check_slop(check: Annotated[SlopReport, Body()], bearer: Annotated[str, AfterValidator(verify_auth_token), Header()]):
|
def check_slop(check: Annotated[SlopReport, Body()], bearer: Annotated[str, AfterValidator(verify_auth_token), Header()]):
|
||||||
slop_results = select_slop(check.slop_urls, DB_ENGINE)
|
slop_results = select_slop(check.slop_urls, DB_ENGINE)
|
||||||
return slop_results
|
return slop_results
|
||||||
|
|
||||||
@@ -112,13 +112,13 @@ async def get_current_user(token: Annotated[str, Depends(oauth2_scheme)]):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@app.post("/token")
|
@app.post("/token")
|
||||||
async def login(form_data: Annotated[OAuth2PasswordRequestForm, Depends()]):
|
def login(form_data: Annotated[OAuth2PasswordRequestForm, Depends()]):
|
||||||
user = get_user(form_data.username, DB_ENGINE)
|
user = get_user(form_data.username, DB_ENGINE)
|
||||||
if not user:
|
if not user:
|
||||||
raise HTTPException(status_code=400, detail="Incorrect username or password")
|
raise HTTPException(status_code=400, detail="Incorrect username or password")
|
||||||
|
|
||||||
@app.post("/signup")
|
@app.post("/signup")
|
||||||
async def signup_form(form_data: Annotated[SignupForm, Form()]):
|
def signup_form(form_data: Annotated[SignupForm, Form()]):
|
||||||
# if we're here, form is validated including the altcha
|
# if we're here, form is validated including the altcha
|
||||||
# check for existing user with the given email
|
# check for existing user with the given email
|
||||||
if get_user(form_data.email, DB_ENGINE):
|
if get_user(form_data.email, DB_ENGINE):
|
||||||
@@ -129,7 +129,7 @@ async def signup_form(form_data: Annotated[SignupForm, Form()]):
|
|||||||
create_user(form_data.email, get_password_hash(form_data.password.get_secret_value()), DB_ENGINE)
|
create_user(form_data.email, get_password_hash(form_data.password.get_secret_value()), DB_ENGINE)
|
||||||
|
|
||||||
@app.get("/altcha-challenge")
|
@app.get("/altcha-challenge")
|
||||||
async def altcha_challenge():
|
def altcha_challenge():
|
||||||
options = ChallengeOptions(
|
options = ChallengeOptions(
|
||||||
expires=datetime.now() + timedelta(minutes=10),
|
expires=datetime.now() + timedelta(minutes=10),
|
||||||
max_number=80000,
|
max_number=80000,
|
||||||
@@ -139,7 +139,7 @@ async def altcha_challenge():
|
|||||||
return challenge
|
return challenge
|
||||||
|
|
||||||
@app.post("/login")
|
@app.post("/login")
|
||||||
async def simple_login(username: Annotated[str, Form()], password: Annotated[str, Form()]):
|
def simple_login(username: Annotated[str, Form()], password: Annotated[str, Form()]):
|
||||||
user = auth_user(username, password, DB_ENGINE)
|
user = auth_user(username, password, DB_ENGINE)
|
||||||
if not user:
|
if not user:
|
||||||
raise HTTPException(status_code=401, detail="Incorrect username or password")
|
raise HTTPException(status_code=401, detail="Incorrect username or password")
|
||||||
|
|||||||
Reference in New Issue
Block a user