Update request state usage to context variable (#853)

* Update request state usage to context variable

* Update context to custom ctx

* Fix the exception interception in opera log

* restore elapsed
This commit is contained in:
Wu Clan
2025-10-16 10:23:39 +08:00
committed by GitHub
parent dd08775c85
commit 6a065797f5
17 changed files with 135 additions and 91 deletions
+2 -1
View File
@@ -4,6 +4,7 @@ from typing import Annotated
from fastapi import APIRouter, Body, Request
from backend.common.context import ctx
from backend.common.response.response_schema import ResponseModel, response_base
from backend.common.security.jwt import DependsJwtAuth
from backend.core.conf import settings
@@ -21,7 +22,7 @@ async def send_email_captcha(
recipients: Annotated[str | list[str], Body(embed=True, description='邮件接收者')],
) -> ResponseModel:
code = ''.join([str(random.randint(1, 9)) for _ in range(6)])
ip = request.state.ip
ip = ctx.ip
await redis_client.set(
f'{settings.EMAIL_CAPTCHA_REDIS_PREFIX}:{ip}',
code,