Merge branch 'main' into feature-ssulbox: SAS 재생 URL·공식 링크 응답 반영
This commit is contained in:
commit
934410a83b
10 files changed
+216
-26
No files matched your search
@@ -30,6 +30,7 @@ from app.home.api.routers.v1.home import _extract_region_from_address
|
||||
from app.lyric.models import Lyric
|
||||
from app.song.models import Song, SongTimestamp
|
||||
from app.utils.creatomate import CreatomateService, LANGUAGE_FONT_MAP
|
||||
from app.utils.upload_blob_as_request import to_playback_url
|
||||
|
||||
from app.database.like_cache import (
|
||||
backfill_user_set,
|
||||
@@ -79,6 +80,55 @@ VIDEO_CREDIT_COST = 1
|
||||
router = APIRouter(prefix="/video", tags=["Video"])
|
||||
|
||||
|
||||
def _place_id_to_site_url(place_id: str | None) -> str | None:
|
||||
"""MarketingIntel.place_id("nv{네이버 place ID}")를 네이버 플레이스 URL로 변환한다.
|
||||
|
||||
크롤링 없이 직접 입력된 업체는 place_id가 없으므로 None을 반환한다.
|
||||
"""
|
||||
if place_id and place_id.startswith("nv") and place_id[2:].isdigit():
|
||||
return f"https://map.naver.com/p/entry/place/{place_id[2:]}"
|
||||
return None
|
||||
|
||||
|
||||
async def _get_official_site_urls(
|
||||
session: AsyncSession, projects: list[Project]
|
||||
) -> dict[int, str | None]:
|
||||
"""프로젝트 목록에 대해 {project_id: 공식 페이지 URL(or None)}을 일괄 조회한다.
|
||||
|
||||
Project.marketing_intelligence(문자열로 저장된 MarketingIntel.id)를 경유해
|
||||
저장된 official_site_url을 우선 사용하고, 컬럼 도입 전 기존 행은
|
||||
place_id 기반 네이버 플레이스 URL로 폴백한다.
|
||||
"""
|
||||
m_id_by_project: dict[int, int] = {}
|
||||
for p in projects:
|
||||
try:
|
||||
if p.marketing_intelligence is not None:
|
||||
m_id_by_project[p.id] = int(p.marketing_intelligence)
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
|
||||
url_by_project: dict[int, str | None] = {p.id: None for p in projects}
|
||||
if not m_id_by_project:
|
||||
return url_by_project
|
||||
|
||||
rows = (
|
||||
await session.execute(
|
||||
select(
|
||||
MarketingIntel.id,
|
||||
MarketingIntel.place_id,
|
||||
MarketingIntel.official_site_url,
|
||||
).where(MarketingIntel.id.in_(set(m_id_by_project.values())))
|
||||
)
|
||||
).all()
|
||||
intel_by_m_id = {m_id: (place_id, site_url) for m_id, place_id, site_url in rows}
|
||||
|
||||
for project_id, m_id in m_id_by_project.items():
|
||||
place_id, site_url = intel_by_m_id.get(m_id, (None, None))
|
||||
url_by_project[project_id] = site_url or _place_id_to_site_url(place_id)
|
||||
return url_by_project
|
||||
|
||||
|
||||
|
||||
|
||||
@router.get(
|
||||
"/generate/{task_id}",
|
||||
@@ -892,7 +942,7 @@ async def download_video(
|
||||
store_name=project.store_name if project else None,
|
||||
region=project.region or _extract_region_from_address(project.detail_region_info) if project else None,
|
||||
task_id=task_id,
|
||||
result_movie_url=video.result_movie_url,
|
||||
result_movie_url=to_playback_url(video.result_movie_url),
|
||||
created_at=video.created_at,
|
||||
)
|
||||
|
||||
@@ -962,7 +1012,7 @@ async def get_all_videos(
|
||||
type=it.ctype,
|
||||
video_id=it.id,
|
||||
store_name=it.store_name,
|
||||
result_movie_url=it.movie_url,
|
||||
result_movie_url=to_playback_url(it.movie_url),
|
||||
poster_url=it.poster_url,
|
||||
title=it.title,
|
||||
description=it.description,
|
||||
@@ -1203,10 +1253,12 @@ async def get_video_detail(
|
||||
liked = False
|
||||
is_liked_by_me = liked
|
||||
|
||||
official_site_url_map = await _get_official_site_urls(session, [project])
|
||||
|
||||
logger.info(f"[get_video_detail] SUCCESS - video_id: {video_id}")
|
||||
return VideoDetailResponse(
|
||||
video_id=video.id,
|
||||
result_movie_url=video.result_movie_url,
|
||||
result_movie_url=to_playback_url(video.result_movie_url),
|
||||
poster_url=video.poster_url,
|
||||
store_name=project.store_name,
|
||||
region=project.region or _extract_region_from_address(project.detail_region_info),
|
||||
@@ -1215,6 +1267,7 @@ async def get_video_detail(
|
||||
created_at=video.created_at,
|
||||
like_count=like_count,
|
||||
is_liked_by_me=is_liked_by_me,
|
||||
official_site_url=official_site_url_map.get(project.id),
|
||||
)
|
||||
|
||||
except HTTPException:
|
||||
|
||||
Reference in new issue
Block a user