xiugai
This commit is contained in:
parent
6a4f21a743
commit
9c18c10cb5
@ -1,6 +1,6 @@
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from fastapi import APIRouter, Body, Query, Form
|
from fastapi import APIRouter, Body, Query, Form,Request
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from ..rotation_service import rotate as rotate_impl, status as status_impl
|
from ..rotation_service import rotate as rotate_impl, status as status_impl
|
||||||
@ -16,24 +16,11 @@ class RotateRequest(BaseModel):
|
|||||||
|
|
||||||
@router.post("/rotate")
|
@router.post("/rotate")
|
||||||
def rotate(
|
def rotate(
|
||||||
# 查询参数
|
req: Optional[RotateRequest] = Body(...),
|
||||||
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),
|
|
||||||
):
|
):
|
||||||
# 优先级:Query > Form > JSON
|
# 优先级:Query > Form > JSON
|
||||||
effective_cityhash = (
|
effective_cityhash = req.cityhash
|
||||||
cityhash_q
|
effective_num = req.num
|
||||||
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))
|
|
||||||
)
|
|
||||||
result = rotate_impl(cityhash=effective_cityhash, num=effective_num)
|
result = rotate_impl(cityhash=effective_cityhash, num=effective_num)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user