refactor: 重构数据库相关功能,移除旧的数据库模块,更新API路由以使用新的数据库接口,增强代码结构和可维护性

This commit is contained in:
iHeyTang
2025-08-14 12:02:01 +08:00
parent 862d48b0ce
commit 58ce862567
11 changed files with 479 additions and 272 deletions

View File

@@ -5,7 +5,12 @@ from fastapi import APIRouter, Body, HTTPException, Path
from fastapi.responses import JSONResponse
from workflow_service import comfyui_client
from workflow_service import database
from workflow_service.database.api import (
save_workflow,
get_all_workflows,
delete_workflow,
get_workflow,
)
workflow_router = APIRouter(
@@ -25,7 +30,7 @@ async def publish_workflow_endpoint(data: dict = Body(...)):
raise HTTPException(
status_code=400, detail="`name` and `workflow` fields are required."
)
await database.save_workflow(name, json.dumps(wf_json))
await save_workflow(name, json.dumps(wf_json))
print(f"Workflow '{name}' published.")
return JSONResponse(
content={"status": "success", "message": f"Workflow '{name}' published."},
@@ -43,7 +48,7 @@ async def get_all_workflows_endpoint():
获取所有工作流
"""
try:
return await database.get_all_workflows()
return await get_all_workflows()
except Exception as e:
raise HTTPException(status_code=500, detail=f"Failed to get workflows: {e}")
@@ -59,7 +64,7 @@ async def delete_workflow_endpoint(
删除工作流
"""
try:
success = await database.delete_workflow(workflow_name)
success = await delete_workflow(workflow_name)
if success:
return {"status": "deleted", "name": workflow_name}
else:
@@ -75,7 +80,7 @@ async def get_one_workflow_endpoint(base_name: str, version: Optional[str] = Non
"""
获取工作流规范
"""
workflow_data = await database.get_workflow(base_name, version)
workflow_data = await get_workflow(base_name, version)
if not workflow_data:
detail = (