This commit is contained in:
aaron 2025-04-11 19:25:11 +08:00
parent 641db511f1
commit 358241d115
2 changed files with 19 additions and 17 deletions

View File

@ -17,7 +17,6 @@ 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)
@ -127,21 +126,21 @@ async def check_tryon_status(
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")
print(completion_url)
# 上传到腾讯云COS url = await cos_service.upload_file_from_url(completion_url)
async with httpx.AsyncClient() as client: tryon_history.status = TryonStatus.COMPLETED
response = await client.get(completion_url) tryon_history.completion_url = url
file_content = response.content await db.commit()
url = await cos_service.upload_file(file_content, "jpg") return StandardResponse(code=200, message="检查试穿状态成功", data={
tryon_history.status = TryonStatus.COMPLETED "history_id": tryon_history.id,
tryon_history.completion_url = url "status": tryon_history.status,
await db.commit() "completion_url": url
})
else: else:
url = tryon_history.completion_url return StandardResponse(code=200, message="检查试穿状态成功", data={
"history_id": tryon_history.id,
return StandardResponse(code=200, message="检查试穿状态成功", data={ "status": tryon_history.status,
"history_id": tryon_history.id, "completion_url": tryon_history.completion_url
"status": tryon_history.status, })
"completion_url": url
})

View File

@ -53,8 +53,11 @@ async def upload_file_from_url(url: str, directory: str = "uploads") -> str:
response = requests.get(url, timeout=10) response = requests.get(url, timeout=10)
response.raise_for_status() response.raise_for_status()
# 获取文件扩展名 # 获取文件扩展名, 要考虑有?的情况
file_extension = os.path.splitext(url)[1] 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: if not file_extension:
# 如果URL没有扩展名根据内容类型判断 # 如果URL没有扩展名根据内容类型判断
content_type = response.headers.get("Content-Type", "") content_type = response.headers.get("Content-Type", "")