This commit is contained in:
wangqifan 2025-10-19 23:16:58 +08:00
parent 6a4f21a743
commit 9c18c10cb5

View File

@ -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