feat: 基础层——phonenumberslite/resolve_region_code/CA字典bug/XFF服务端优先

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-10-08 16:48:55 +08:00
parent 1d4e282b14
commit 1c4d204906
5 changed files with 47 additions and 5 deletions
+8 -2
View File
@@ -32,13 +32,19 @@ class SessionRequest(BaseModel):
@router.post("/session")
async def chat_session(req: SessionRequest):
async def chat_session(req: SessionRequest, request: Request):
"""Resume an active conversation by session_id, or create a new app one.
`context` flows into `create_conversation` where it is whitelisted into
`raw_info` (only when non-None). `client_info` is stored for analytics only
(ip/ua/device-id/lang) and never fed to the AI prompt.
"""
# 服务端 XFF 优先于客户端自报 ip(客户端自报可伪造,可伪造面最小)
xf = request.headers.get("x-forwarded-for", "").split(",")[0].strip()
client_info = dict(req.client_info or {})
if xf:
client_info["ip"] = xf
async with async_session() as db:
manager = ConversationManager(db)
if req.session_id:
@@ -51,7 +57,7 @@ async def chat_session(req: SessionRequest):
}
conv = await manager.create_conversation(
source=ConversationSource.app,
client_info=req.client_info,
client_info=client_info,
context=req.context,
)
return {