feat: 좋아요·댓글·SNS 업로드를 콘텐츠 종류 공용으로 통합
This commit is contained in:
1 parent
ed1ba71bfe
commit
fb8febe462
7 files changed
+318
-109
No files matched your search
@@ -5,8 +5,6 @@ Social Upload Background Task
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
@@ -21,11 +19,12 @@ from config import social_upload_settings
|
||||
from app.dashboard.tasks import insert_dashboard
|
||||
from app.database.session import BackgroundSessionLocal
|
||||
from app.social.constants import SocialPlatform, UploadStatus
|
||||
from app.social.exceptions import TokenExpiredError, UploadError, UploadQuotaExceededError
|
||||
from app.social.exceptions import TokenExpiredError, UploadQuotaExceededError
|
||||
from app.social.models import SocialUpload
|
||||
from app.social.services import social_account_service
|
||||
from app.social.uploader import get_uploader
|
||||
from app.social.uploader.base import UploadMetadata
|
||||
from app.ssulbox.models import SsulContent
|
||||
from app.user.models import SocialAccount
|
||||
from app.video.models import Video
|
||||
|
||||
@@ -169,16 +168,27 @@ async def process_social_upload(upload_id: int) -> None:
|
||||
logger.error(f"[SOCIAL_UPLOAD] 업로드 레코드 없음 - upload_id: {upload_id}")
|
||||
return
|
||||
|
||||
# 2. Video 정보 조회
|
||||
video_result = await session.execute(
|
||||
select(Video).where(Video.id == upload.video_id)
|
||||
)
|
||||
video = video_result.scalar_one_or_none()
|
||||
# 2. 대상 영상 조회.
|
||||
# 병합 스키마: video_id / content_id 중 정확히 하나만 채워져 있다(CHECK).
|
||||
# 채워진 쪽이 곧 종류다 — 썰박스면 ssul_content.video_url 을 쓴다.
|
||||
if upload.content_id is not None:
|
||||
content_result = await session.execute(
|
||||
select(SsulContent).where(SsulContent.id == upload.content_id)
|
||||
)
|
||||
content = content_result.scalar_one_or_none()
|
||||
source_url = content.video_url if content else None
|
||||
else:
|
||||
video_result = await session.execute(
|
||||
select(Video).where(Video.id == upload.video_id)
|
||||
)
|
||||
video = video_result.scalar_one_or_none()
|
||||
source_url = video.result_movie_url if video else None
|
||||
|
||||
if not video or not video.result_movie_url:
|
||||
if not source_url:
|
||||
logger.error(
|
||||
f"[SOCIAL_UPLOAD] 영상 없음 또는 URL 없음 - "
|
||||
f"upload_id: {upload_id}, video_id: {upload.video_id}"
|
||||
f"upload_id: {upload_id}, video_id: {upload.video_id}, "
|
||||
f"content_id: {upload.content_id}"
|
||||
)
|
||||
await _update_upload_status(
|
||||
upload_id=upload_id,
|
||||
@@ -206,7 +216,7 @@ async def process_social_upload(upload_id: int) -> None:
|
||||
return
|
||||
|
||||
# 필요한 정보 저장
|
||||
video_url = video.result_movie_url
|
||||
video_url = source_url
|
||||
platform = SocialPlatform(upload.platform)
|
||||
upload_title = upload.title
|
||||
upload_description = upload.description
|
||||
@@ -347,7 +357,7 @@ async def process_social_upload(upload_id: int) -> None:
|
||||
f"upload_id: {upload_id}, error: {result.error_message}"
|
||||
)
|
||||
|
||||
except UploadQuotaExceededError as e:
|
||||
except UploadQuotaExceededError:
|
||||
logger.error(f"[SOCIAL_UPLOAD] API 할당량 초과 - upload_id: {upload_id}")
|
||||
await _update_upload_status(
|
||||
upload_id=upload_id,
|
||||
|
||||
Reference in new issue
Block a user