This commit is contained in:
aaron 2025-04-11 16:04:02 +08:00
parent 9c4c393426
commit 641db511f1

View File

@ -17,6 +17,7 @@ from app.schemas.tryon import TryonHistoryModel
from app.core.exceptions import BusinessError from app.core.exceptions import BusinessError
from app.services import cos as cos_service from app.services import cos as cos_service
from sqlalchemy import select from sqlalchemy import select
import httpx
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
@ -121,24 +122,26 @@ async def check_tryon_status(
if not tryon_history: if not tryon_history:
raise BusinessError(code=404, message="试穿历史不存在") raise BusinessError(code=404, message="试穿历史不存在")
dashscope_service = DashScopeService() if tryon_history.status != TryonStatus.COMPLETED:
completion = await dashscope_service.check_tryon_status(tryon_history.task_id) dashscope_service = DashScopeService()
if completion.get("status") == "SUCCEEDED": completion = await dashscope_service.check_tryon_status(tryon_history.task_id)
completion_url = completion.get("image_url") if completion.get("status") == "SUCCEEDED":
completion_url = completion.get("image_url")
url = await cos_service.upload_file_from_url(completion_url) # 上传到腾讯云COS
tryon_history.status = TryonStatus.COMPLETED async with httpx.AsyncClient() as client:
tryon_history.completion_url = url response = await client.get(completion_url)
await db.commit() file_content = response.content
return StandardResponse(code=200, message="检查试穿状态成功", data={ url = await cos_service.upload_file(file_content, "jpg")
"history_id": tryon_history.id, tryon_history.status = TryonStatus.COMPLETED
"status": tryon_history.status, tryon_history.completion_url = url
"completion_url": url await db.commit()
})
else: else:
return StandardResponse(code=200, message="检查试穿状态成功", data={ url = tryon_history.completion_url
"history_id": tryon_history.id,
"status": tryon_history.status, return StandardResponse(code=200, message="检查试穿状态成功", data={
"completion_url": None "history_id": tryon_history.id,
}) "status": tryon_history.status,
"completion_url": url
})