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