diff --git a/app/social/worker/upload_task.py b/app/social/worker/upload_task.py index 6c5a9c9..3c99ca1 100644 --- a/app/social/worker/upload_task.py +++ b/app/social/worker/upload_task.py @@ -20,6 +20,7 @@ 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, UploadQuotaExceededError +from app.p2v.models import PosterAliveTask from app.social.models import SocialUpload from app.social.services import social_account_service from app.social.uploader import get_uploader @@ -143,6 +144,28 @@ async def _increment_retry_count(upload_id: int) -> int: return 0 +async def _resolve_source_url(session, upload: SocialUpload) -> Optional[str]: + """업로드가 가리키는 콘텐츠 종류의 영상 URL. 병합 스키마라 채워진 FK 가 곧 종류다.""" + if upload.p2v_video_id is not None: + row = ( + await session.execute( + select(PosterAliveTask).where(PosterAliveTask.id == upload.p2v_video_id) + ) + ).scalar_one_or_none() + return row.video_url if row else None + if upload.content_id is not None: + row = ( + await session.execute( + select(SsulContent).where(SsulContent.id == upload.content_id) + ) + ).scalar_one_or_none() + return row.video_url if row else None + row = ( + await session.execute(select(Video).where(Video.id == upload.video_id)) + ).scalar_one_or_none() + return row.result_movie_url if row else None + + async def process_social_upload(upload_id: int) -> None: """ 소셜 미디어 업로드 처리 @@ -168,27 +191,14 @@ async def process_social_upload(upload_id: int) -> None: logger.error(f"[SOCIAL_UPLOAD] 업로드 레코드 없음 - upload_id: {upload_id}") return - # 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 + # 2. 대상 영상 조회. video_id / content_id / p2v_video_id 중 정확히 하나만 채워져 있다(CHECK). + source_url = await _resolve_source_url(session, upload) if not source_url: logger.error( f"[SOCIAL_UPLOAD] 영상 없음 또는 URL 없음 - " f"upload_id: {upload_id}, video_id: {upload.video_id}, " - f"content_id: {upload.content_id}" + f"content_id: {upload.content_id}, p2v_video_id: {upload.p2v_video_id}" ) await _update_upload_status( upload_id=upload_id,