update
This commit is contained in:
parent
9c4c393426
commit
641db511f1
@ -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
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user