diff --git a/app/routers/proxy.py b/app/routers/proxy.py index 321b7c3..544e5c6 100644 --- a/app/routers/proxy.py +++ b/app/routers/proxy.py @@ -1,6 +1,6 @@ from typing import Optional -from fastapi import APIRouter, Body, Query, Form +from fastapi import APIRouter, Body, Query, Form,Request from pydantic import BaseModel from ..rotation_service import rotate as rotate_impl, status as status_impl @@ -16,24 +16,11 @@ class RotateRequest(BaseModel): @router.post("/rotate") def rotate( - # 查询参数 - cityhash_q: Optional[str] = Query(None, alias="cityhash"), - num_q: Optional[int] = Query(None, alias="num"), - # 表单参数(multipart/form-data 或 application/x-www-form-urlencoded) - cityhash_f: Optional[str] = Form(None), - num_f: Optional[int] = Form(None), - # JSON 请求体(application/json) - req: Optional[RotateRequest] = Body(None), + req: Optional[RotateRequest] = Body(...), ): # 优先级:Query > Form > JSON - effective_cityhash = ( - cityhash_q - if cityhash_q is not None - else (cityhash_f if cityhash_f is not None else (req.cityhash if req else None)) - ) - effective_num = ( - num_q if num_q is not None else (num_f if num_f is not None else (req.num if req else None)) - ) + effective_cityhash = req.cityhash + effective_num = req.num result = rotate_impl(cityhash=effective_cityhash, num=effective_num) return result