From 81a554193c7673239322a15d6b225e0fa2c35c93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=84=B1=EA=B2=BD?= Date: Fri, 16 Oct 2026 10:25:36 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=97=85=EB=A1=9C=EB=93=9C=20=EC=9B=8C?= =?UTF-8?q?=EC=BB=A4=EA=B0=80=20p2v=5Fvideo=20=EC=9B=90=EB=B3=B8=20URL=20?= =?UTF-8?q?=EC=9D=84=20=EC=9D=BD=EB=8F=84=EB=A1=9D=20=EB=B6=84=EA=B8=B0=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/social/worker/upload_task.py | 42 ++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 16 deletions(-) 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,