feat(ssulbox): SNS 제목·설명·태그를 ssul_content에 저장

영상과 같이 업로드·SEO 결과를 행에 남기고, 다음 요청부터는 DB 값을 쓴다.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
skkimandCursor committed 2026-08-19 15:31:44 +09:00
1 parent fde48e8674
commit e47a97476d
9 files changed
+108 -36

No files matched your search

+14 -8
View File
@@ -52,7 +52,7 @@ class SeoService:
)
if has_stored_sns_metadata(video):
return self._response_from_video(video)
return self._response_from_row(video)
result = await self.generate_and_save_for_video(video.id, session)
if result is None:
@@ -90,6 +90,9 @@ class SeoService:
status_code=404, detail="콘텐츠를 찾을 수 없습니다."
)
if has_stored_sns_metadata(content):
return self._response_from_row(content)
input_data = {
"store_name": content.store_name or "",
"region": content.region or "",
@@ -100,12 +103,15 @@ class SeoService:
out = await chatgpt.generate_structured_output(
get_ssul_upload_prompt(), input_data
)
return YoutubeDescriptionResponse(
result = YoutubeDescriptionResponse(
title=out.title,
description=out.description,
keywords=out.keywords,
)
apply_sns_metadata(content, result.title, result.description, result.keywords)
await session.commit()
logger.info(f"[SEO_SERVICE] Saved ssul metadata - content_id: {content_id}")
return result
except HTTPException:
raise
@@ -129,7 +135,7 @@ class SeoService:
return None
if has_stored_sns_metadata(video):
return self._response_from_video(video)
return self._response_from_row(video)
result = await self._generate_seo_description(video.task_id, session)
apply_sns_metadata(video, result.title, result.description, result.keywords)
@@ -241,11 +247,11 @@ class SeoService:
detail=f"유튜브 SEO 생성에 실패했습니다. : {str(e)}",
)
def _response_from_video(self, video: Video) -> YoutubeDescriptionResponse:
def _response_from_row(self, row) -> YoutubeDescriptionResponse:
return YoutubeDescriptionResponse(
title=video.title or "",
description=video.description or "",
keywords=list(video.hashtags or []),
title=row.title or "",
description=row.description or "",
keywords=list(row.hashtags or []),
)
+23 -14
View File
@@ -1,36 +1,45 @@
"""SNS 업로드용 영상 메타데이터 비교/반영 헬퍼."""
"""SNS 업로드용 메타데이터 비교/반영 헬퍼.
from app.video.models import Video
`video` 와 `ssul_content` 모두 `title` / `description` / `hashtags` 를 갖는다.
"""
from typing import Protocol
def has_stored_sns_metadata(video: Video) -> bool:
"""video 행에 SNS 제목이 이미 저장되어 있는지 확인합니다."""
return bool(video.title)
class SnsMetadataTarget(Protocol):
title: str | None
description: str | None
hashtags: list | None
def has_stored_sns_metadata(row: SnsMetadataTarget) -> bool:
"""행에 SNS 제목이 이미 저장되어 있는지 확인합니다."""
return bool(row.title)
def sns_metadata_changed(
video: Video,
row: SnsMetadataTarget,
title: str,
description: str | None,
tags: list[str] | None,
) -> bool:
"""게시 폼 값이 저장된 SNS 메타데이터와 다른지 비교합니다."""
stored_tags = list(video.hashtags or [])
stored_tags = list(row.hashtags or [])
incoming_tags = list(tags or [])
return (
(video.title or "") != title
or (video.description or "") != (description or "")
(row.title or "") != title
or (row.description or "") != (description or "")
or stored_tags != incoming_tags
)
def apply_sns_metadata(
video: Video,
row: SnsMetadataTarget,
title: str,
description: str | None,
hashtags: list[str] | None,
) -> None:
"""video 행에 SNS 메타데이터를 반영합니다."""
video.title = title
video.description = description
video.hashtags = list(hashtags or [])
"""행에 SNS 메타데이터를 반영합니다."""
row.title = title
row.description = description
row.hashtags = list(hashtags or [])
+5 -5
View File
@@ -89,6 +89,7 @@ class SocialUploadService:
video_id=body.video_id,
detail="영상이 아직 준비되지 않았습니다. 영상 생성이 완료된 후 시도해주세요.",
)
target = content
else:
target_col = SocialUpload.video_id
# video 에는 user_uuid 가 없다 — 소유권은 project 에 있으므로 조인한다.
@@ -113,13 +114,12 @@ class SocialUploadService:
video_id=body.video_id,
detail="영상이 아직 준비되지 않았습니다. 영상 생성이 완료된 후 시도해주세요.",
)
target = video
if body.content_type != "ssul" and sns_metadata_changed(
video, body.title, body.description, body.tags
):
apply_sns_metadata(video, body.title, body.description, body.tags)
if sns_metadata_changed(target, body.title, body.description, body.tags):
apply_sns_metadata(target, body.title, body.description, body.tags)
logger.info(
f"[UPLOAD_SERVICE] video SNS 메타데이터 갱신 - video_id: {body.video_id}"
f"[UPLOAD_SERVICE] SNS 메타데이터 갱신 - type: {body.content_type}, id: {body.video_id}"
)
# 2. 소셜 계정 조회 및 소유권 검증