feat: 좋아요·댓글·SNS 업로드를 콘텐츠 종류 공용으로 통합

This commit is contained in:
skkim committed 2026-08-11 11:03:03 +09:00
1 parent ed1ba71bfe
commit fb8febe462
7 files changed
+318 -109

No files matched your search

+60 -19
View File
@@ -28,6 +28,8 @@ from app.social.schemas import (
from app.social.services.account_service import SocialAccountService
from app.social.worker.upload_task import process_social_upload
from app.user.models import User
from app.home.models import Project
from app.ssulbox.models import SsulContent
from app.video.models import Video
logger = logging.getLogger(__name__)
@@ -55,26 +57,61 @@ class SocialUploadService:
logger.info(
f"[UPLOAD_SERVICE] 업로드 요청 - "
f"user_uuid: {current_user.user_uuid}, "
f"video_id: {body.video_id}, "
f"type: {body.content_type}, id: {body.video_id}, "
f"social_account_id: {body.social_account_id}"
)
# 1. 영상 조회 및 검증
video_result = await session.execute(
select(Video).where(Video.id == body.video_id)
)
video = video_result.scalar_one_or_none()
# 1. 대상 조회 및 검증.
# video.id 와 ssul_content.id 는 값이 겹치는 독립 시퀀스라 content_type 으로
# 정확히 한 테이블만 봐야 한다 — 아니면 남의 다른 콘텐츠가 업로드된다.
# `target_col` 은 이후 중복 확인·채번에서도 같은 컬럼을 쓰기 위한 것이다.
# ⚠️ 소유자 필터가 필수다. 대상 id 는 클라이언트가 보내는 값이라, 안 거르면
# **남의 콘텐츠를 자기 SNS 채널에 업로드**할 수 있다(계정 소유권만 검증하고
# 콘텐츠 소유권을 안 보면 IDOR 이 된다).
if body.content_type == "ssul":
target_col = SocialUpload.content_id
content = (
await session.execute(
select(SsulContent).where(
SsulContent.id == body.video_id,
SsulContent.user_uuid == current_user.user_uuid,
SsulContent.is_deleted.is_(False),
)
)
).scalar_one_or_none()
if not content:
logger.warning(f"[UPLOAD_SERVICE] 썰박스 콘텐츠 없음 - id: {body.video_id}")
raise VideoNotFoundError(video_id=body.video_id)
if content.status != "done" or not content.video_url:
logger.warning(f"[UPLOAD_SERVICE] 썰박스 영상 미완성 - id: {body.video_id}")
raise VideoNotFoundError(
video_id=body.video_id,
detail="영상이 아직 준비되지 않았습니다. 영상 생성이 완료된 후 시도해주세요.",
)
else:
target_col = SocialUpload.video_id
# video 에는 user_uuid 가 없다 — 소유권은 project 에 있으므로 조인한다.
video = (
await session.execute(
select(Video)
.join(Project, Video.project_id == Project.id)
.where(
Video.id == body.video_id,
Project.user_uuid == current_user.user_uuid,
)
)
).scalar_one_or_none()
if not video:
logger.warning(f"[UPLOAD_SERVICE] 영상 없음 - video_id: {body.video_id}")
raise VideoNotFoundError(video_id=body.video_id)
if not video:
logger.warning(f"[UPLOAD_SERVICE] 영상 없음 - video_id: {body.video_id}")
raise VideoNotFoundError(video_id=body.video_id)
if not video.result_movie_url:
logger.warning(f"[UPLOAD_SERVICE] 영상 URL 없음 - video_id: {body.video_id}")
raise VideoNotFoundError(
video_id=body.video_id,
detail="영상이 아직 준비되지 않았습니다. 영상 생성이 완료된 후 시도해주세요.",
)
if not video.result_movie_url:
logger.warning(f"[UPLOAD_SERVICE] 영상 URL 없음 - video_id: {body.video_id}")
raise VideoNotFoundError(
video_id=body.video_id,
detail="영상이 아직 준비되지 않았습니다. 영상 생성이 완료된 후 시도해주세요.",
)
# 2. 소셜 계정 조회 및 소유권 검증
account = await self._account_service.get_account_by_id(
@@ -96,7 +133,7 @@ class SocialUploadService:
# 3-1. 진행 중인 업로드 확인 (즉시 pending 또는 uploading)
in_progress_result = await session.execute(
select(SocialUpload).where(
SocialUpload.video_id == body.video_id,
target_col == body.video_id,
SocialUpload.social_account_id == account.id,
SocialUpload.status.in_([UploadStatus.PENDING.value, UploadStatus.UPLOADING.value]),
or_(
@@ -122,7 +159,7 @@ class SocialUploadService:
# 3-2. 미래 예약 업로드 확인
scheduled_result = await session.execute(
select(SocialUpload).where(
SocialUpload.video_id == body.video_id,
target_col == body.video_id,
SocialUpload.social_account_id == account.id,
SocialUpload.status == UploadStatus.PENDING.value,
SocialUpload.scheduled_at.isnot(None),
@@ -148,7 +185,7 @@ class SocialUploadService:
# 4. 업로드 순번 계산
max_seq_result = await session.execute(
select(func.coalesce(func.max(SocialUpload.upload_seq), 0)).where(
SocialUpload.video_id == body.video_id,
target_col == body.video_id,
SocialUpload.social_account_id == account.id,
)
)
@@ -157,7 +194,9 @@ class SocialUploadService:
# 5. 새 업로드 레코드 생성
social_upload = SocialUpload(
user_uuid=current_user.user_uuid,
video_id=body.video_id,
# 종류에 따라 둘 중 하나만 채운다 (CHECK ck_social_upload_one_target 이 강제)
video_id=body.video_id if body.content_type == "video" else None,
content_id=body.video_id if body.content_type == "ssul" else None,
social_account_id=account.id,
upload_seq=next_seq,
platform=account.platform,
@@ -225,6 +264,7 @@ class SocialUploadService:
return SocialUploadStatusResponse(
upload_id=upload.id,
video_id=upload.video_id,
content_id=upload.content_id,
social_account_id=upload.social_account_id,
upload_seq=upload.upload_seq,
platform=upload.platform,
@@ -318,6 +358,7 @@ class SocialUploadService:
SocialUploadHistoryItem(
upload_id=upload.id,
video_id=upload.video_id,
content_id=upload.content_id,
social_account_id=upload.social_account_id,
upload_seq=upload.upload_seq,
platform=upload.platform,