fix: 썰박스 포스터·SNS 메타데이터 생성 및 공유 미리보기 수정
This commit is contained in:
1 parent
5fcb964d7f
commit
048a8f36a8
5 files changed
+178
-35
No files matched your search
@@ -170,6 +170,7 @@ def _build_share_html(
|
||||
)
|
||||
image_url = _absolute_http_url(poster_url) or fallback_image_url
|
||||
canonical_url = _absolute_http_url(share_url) or detail_url
|
||||
image_size_tags = _og_image_size_tags(image_url, fallback_image_url)
|
||||
|
||||
escaped_title = escape(title, quote=True)
|
||||
escaped_description = escape(description, quote=True)
|
||||
@@ -190,8 +191,8 @@ def _build_share_html(
|
||||
<meta property="og:description" content="{escaped_description}">
|
||||
<meta property="og:image" content="{escaped_image_url}">
|
||||
<meta property="og:image:alt" content="{escaped_title}">
|
||||
<meta property="og:url" content="{escaped_canonical_url}">
|
||||
<meta property="og:type" content="video.other">
|
||||
{image_size_tags} <meta property="og:url" content="{escaped_canonical_url}">
|
||||
<meta property="og:type" content="website">
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:title" content="{escaped_title}">
|
||||
@@ -206,7 +207,13 @@ def _build_share_html(
|
||||
<a id="continue-link" href="{escaped_detail_url}">콘텐츠 보기</a>
|
||||
</main>
|
||||
<script>
|
||||
window.location.replace(document.getElementById("continue-link").href);
|
||||
(function () {{
|
||||
var ua = navigator.userAgent || "";
|
||||
if (/bot|crawl|spider|slurp|facebookexternalhit|Facebot|Twitterbot|LinkedInBot|Pinterest|Slackbot|Telegram|WhatsApp|Discord|Kakao|kakaotalk|Embedly|redditbot|Applebot/i.test(ua)) {{
|
||||
return;
|
||||
}}
|
||||
window.location.replace(document.getElementById("continue-link").href);
|
||||
}})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -271,28 +278,54 @@ def _resolve_default_image_url(
|
||||
|
||||
우선순위:
|
||||
1. ``SHARE_DEFAULT_IMAGE_URL`` (.env)
|
||||
2. 공유 API 호스트 ``/static/images/ado2_image.png``
|
||||
2. 공유 URL과 같은 API 베이스 ``.../static/images/ado2_image.png``
|
||||
(``/api/video/share/1`` 이면 ``/api/static/...``)
|
||||
3. ``SHARE_FRONTEND_URL`` + ``/assets/images/ado2_image.png``
|
||||
"""
|
||||
configured_absolute_url = _absolute_http_url(configured_url)
|
||||
if configured_absolute_url:
|
||||
return configured_absolute_url
|
||||
|
||||
share_origin = _origin_from_url(share_url)
|
||||
if share_origin:
|
||||
return f"{share_origin}{DEFAULT_SHARE_IMAGE_STATIC_PATH}"
|
||||
share_api_base = _api_base_from_share_url(share_url)
|
||||
if share_api_base:
|
||||
return f"{share_api_base}{DEFAULT_SHARE_IMAGE_STATIC_PATH}"
|
||||
|
||||
return f"{frontend_base}{DEFAULT_SHARE_IMAGE_PATH}"
|
||||
|
||||
|
||||
def _origin_from_url(value: str) -> str | None:
|
||||
"""URL에서 scheme + host(+port) origin만 추출합니다."""
|
||||
absolute_url = _absolute_http_url(value)
|
||||
_DEFAULT_OG_IMAGE_SIZE = (385, 385)
|
||||
|
||||
|
||||
def _og_image_size_tags(image_url: str, fallback_image_url: str) -> str:
|
||||
"""폴백 로고처럼 크기를 아는 이미지에만 width/height 메타를 붙입니다."""
|
||||
if image_url != fallback_image_url:
|
||||
return ""
|
||||
width, height = _DEFAULT_OG_IMAGE_SIZE
|
||||
return (
|
||||
f' <meta property="og:image:width" content="{width}">\n'
|
||||
f' <meta property="og:image:height" content="{height}">\n'
|
||||
)
|
||||
|
||||
|
||||
def _api_base_from_share_url(share_url: str) -> str | None:
|
||||
"""공유 URL에서 API 베이스를 만듭니다. ``/api/video/share/1`` → ``https://host/api``."""
|
||||
absolute_url = _absolute_http_url(share_url)
|
||||
if not absolute_url:
|
||||
return None
|
||||
|
||||
parts = urlsplit(absolute_url)
|
||||
return urlunsplit((parts.scheme, parts.netloc, "", "", ""))
|
||||
origin = urlunsplit((parts.scheme, parts.netloc, "", "", ""))
|
||||
path = parts.path or ""
|
||||
prefix = ""
|
||||
for marker in ("/video/share/", "/ssul/share/"):
|
||||
idx = path.find(marker)
|
||||
if idx >= 0:
|
||||
prefix = path[:idx].rstrip("/")
|
||||
break
|
||||
else:
|
||||
return origin
|
||||
|
||||
return f"{origin}{prefix}" if prefix else origin
|
||||
|
||||
|
||||
def _absolute_http_url(value: str | None) -> str | None:
|
||||
|
||||
Reference in new issue
Block a user