refactor: 更新API路由参数解析,使用Body获取请求数据,简化请求处理逻辑
This commit is contained in:
parent
09910c63b8
commit
862d48b0ce
|
|
@ -1,7 +1,8 @@
|
|||
import json
|
||||
from typing import Optional
|
||||
from typing import Dict, Optional
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Request
|
||||
from fastapi import APIRouter, Body, HTTPException, Request
|
||||
from fastapi.openapi.models import RequestBody
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from workflow_service import comfyui_client, database
|
||||
|
|
@ -14,15 +15,15 @@ run_router = APIRouter(
|
|||
|
||||
@run_router.post("")
|
||||
async def run_workflow(
|
||||
request: Request, workflow_name: str, workflow_version: Optional[str] = None
|
||||
workflow_name: str,
|
||||
workflow_version: Optional[str] = None,
|
||||
data: Dict = Body(...),
|
||||
):
|
||||
"""
|
||||
异步执行工作流。
|
||||
立即返回任务ID,调用者可以通过任务ID查询执行状态。
|
||||
"""
|
||||
try:
|
||||
data = await request.json()
|
||||
|
||||
if not workflow_name:
|
||||
raise HTTPException(status_code=400, detail="`workflow_name` 字段是必需的")
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import json
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import Request, HTTPException
|
||||
from fastapi import Body, HTTPException
|
||||
from fastapi.responses import JSONResponse
|
||||
from workflow_service import comfyui_client, database
|
||||
from ._base import runx_router
|
||||
|
|
@ -12,7 +12,7 @@ RUNX_WORKFLOW_NAME = "测试"
|
|||
|
||||
@runx_router.post(f"/{RUNX_NAME}")
|
||||
async def model_with_multi_dress(
|
||||
request: Request,
|
||||
data: dict = Body(...),
|
||||
workflow_version: Optional[str] = None,
|
||||
):
|
||||
"""
|
||||
|
|
@ -34,7 +34,6 @@ async def model_with_multi_dress(
|
|||
api_spec = comfyui_client.parse_api_spec(workflow)
|
||||
|
||||
# 将请求拆分为多个请求
|
||||
data = await request.json()
|
||||
batch_data = _convert(data)
|
||||
|
||||
# 提交到队列
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import json
|
||||
from typing import Optional, List
|
||||
|
||||
from fastapi import APIRouter, Request, HTTPException, Path
|
||||
from fastapi import APIRouter, Body, HTTPException, Path
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from workflow_service import comfyui_client
|
||||
|
|
@ -15,12 +15,11 @@ workflow_router = APIRouter(
|
|||
|
||||
|
||||
@workflow_router.post("", status_code=201)
|
||||
async def publish_workflow_endpoint(request: Request):
|
||||
async def publish_workflow_endpoint(data: dict = Body(...)):
|
||||
"""
|
||||
发布工作流
|
||||
"""
|
||||
try:
|
||||
data = await request.json()
|
||||
name, wf_json = data.get("name"), data.get("workflow")
|
||||
if not name or not wf_json:
|
||||
raise HTTPException(
|
||||
|
|
|
|||
Loading…
Reference in New Issue