update
This commit is contained in:
parent
641db511f1
commit
358241d115
@ -17,7 +17,6 @@ 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)
|
||||
@ -127,21 +126,21 @@ async def check_tryon_status(
|
||||
completion = await dashscope_service.check_tryon_status(tryon_history.task_id)
|
||||
if completion.get("status") == "SUCCEEDED":
|
||||
completion_url = completion.get("image_url")
|
||||
print(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")
|
||||
url = await cos_service.upload_file_from_url(completion_url)
|
||||
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": tryon_history.completion_url
|
||||
})
|
||||
|
||||
@ -53,8 +53,11 @@ async def upload_file_from_url(url: str, directory: str = "uploads") -> str:
|
||||
response = requests.get(url, timeout=10)
|
||||
response.raise_for_status()
|
||||
|
||||
# 获取文件扩展名
|
||||
# 获取文件扩展名, 要考虑有?的情况
|
||||
file_extension = os.path.splitext(url)[1]
|
||||
if "?" in file_extension:
|
||||
file_extension = file_extension.split("?")[0]
|
||||
logger.info(f"文件扩展名: {file_extension}")
|
||||
if not file_extension:
|
||||
# 如果URL没有扩展名,根据内容类型判断
|
||||
content_type = response.headers.get("Content-Type", "")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user