From 641db511f1db8b16b6224417bde8cccf58c11642 Mon Sep 17 00:00:00 2001 From: aaron <> Date: Fri, 11 Apr 2025 16:04:02 +0800 Subject: [PATCH] update --- app/api/v1/tryon.py | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/app/api/v1/tryon.py b/app/api/v1/tryon.py index ffe8a85..b39aa3f 100644 --- a/app/api/v1/tryon.py +++ b/app/api/v1/tryon.py @@ -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="试穿历史不存在") - 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") + 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) - tryon_history.status = TryonStatus.COMPLETED - tryon_history.completion_url = url - await db.commit() + # 上传到腾讯云COS + async with httpx.AsyncClient() as client: + response = await client.get(completion_url) + file_content = response.content - return StandardResponse(code=200, message="检查试穿状态成功", data={ - "history_id": tryon_history.id, - "status": tryon_history.status, - "completion_url": url - }) + url = await cos_service.upload_file(file_content, "jpg") + tryon_history.status = TryonStatus.COMPLETED + tryon_history.completion_url = url + await db.commit() else: - return StandardResponse(code=200, message="检查试穿状态成功", data={ - "history_id": tryon_history.id, - "status": tryon_history.status, - "completion_url": None - }) + url = tryon_history.completion_url + + return StandardResponse(code=200, message="检查试穿状态成功", data={ + "history_id": tryon_history.id, + "status": tryon_history.status, + "completion_url": url + })