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.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="试穿历史不存在")
|
||||||
|
|
||||||
|
if tryon_history.status != TryonStatus.COMPLETED:
|
||||||
dashscope_service = DashScopeService()
|
dashscope_service = DashScopeService()
|
||||||
completion = await dashscope_service.check_tryon_status(tryon_history.task_id)
|
completion = await dashscope_service.check_tryon_status(tryon_history.task_id)
|
||||||
if completion.get("status") == "SUCCEEDED":
|
if completion.get("status") == "SUCCEEDED":
|
||||||
completion_url = completion.get("image_url")
|
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.status = TryonStatus.COMPLETED
|
||||||
tryon_history.completion_url = url
|
tryon_history.completion_url = url
|
||||||
await db.commit()
|
await db.commit()
|
||||||
|
else:
|
||||||
|
url = tryon_history.completion_url
|
||||||
|
|
||||||
return StandardResponse(code=200, message="检查试穿状态成功", data={
|
return StandardResponse(code=200, message="检查试穿状态成功", data={
|
||||||
"history_id": tryon_history.id,
|
"history_id": tryon_history.id,
|
||||||
"status": tryon_history.status,
|
"status": tryon_history.status,
|
||||||
"completion_url": url
|
"completion_url": url
|
||||||
})
|
})
|
||||||
else:
|
|
||||||
return StandardResponse(code=200, message="检查试穿状态成功", data={
|
|
||||||
"history_id": tryon_history.id,
|
|
||||||
"status": tryon_history.status,
|
|
||||||
"completion_url": None
|
|
||||||
})
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user