fix: 공유 썸네일 크기 조절
This commit is contained in:
1 parent
a727d4f1ac
commit
e8a268e7b4
6 files changed
+374
-47
No files matched your search
@@ -5,7 +5,7 @@ castad 는 `/api/*` prefix 를 쓰지 않고 도메인별 prefix 를 쓰므로 `
|
||||
인증은 castad `get_current_user` 를 그대로 쓴다(원본의 auth 라우터·JWT 는 폐기).
|
||||
"""
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, Response
|
||||
from fastapi.responses import HTMLResponse
|
||||
from sqlalchemy import func, select
|
||||
|
||||
@@ -29,6 +29,7 @@ from app.user.dependencies.auth import get_current_user, get_current_user_option
|
||||
from app.user.models import User
|
||||
# 좋아요는 castad video_reaction 에 병합돼 있다 (썰박스 행은 content_id 가 채워짐)
|
||||
from app.video.models import VideoReaction
|
||||
from app.video.services.share_image import build_og_card
|
||||
from app.video.services.share_page import (
|
||||
build_ssul_share_html,
|
||||
get_ssul_share_data,
|
||||
@@ -230,6 +231,42 @@ async def get_ssul_share_page(
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/share/{content_id}/og.jpg",
|
||||
summary="썰박스 공유 카드 이미지",
|
||||
description=(
|
||||
"포스터를 1200x630 카드로 합성해 반환합니다. 세로 포스터는 좌우 여백을 "
|
||||
"블러 배경으로 채워 잘리지 않게 합니다."
|
||||
),
|
||||
response_class=Response,
|
||||
responses={
|
||||
200: {"content": {"image/jpeg": {}}, "description": "공유 카드 JPEG 반환"},
|
||||
404: {"description": "공유 가능한 완료 콘텐츠를 찾을 수 없음"},
|
||||
},
|
||||
)
|
||||
async def get_ssul_share_og_image(
|
||||
content_id: int,
|
||||
session: AsyncSession = Depends(get_session),
|
||||
) -> Response:
|
||||
"""크롤러가 링크 카드에 쓸 규격 이미지를 반환합니다."""
|
||||
share_data = await get_ssul_share_data(session, content_id)
|
||||
if share_data is None:
|
||||
raise HTTPException(status_code=404, detail="공유 가능한 콘텐츠를 찾을 수 없습니다.")
|
||||
|
||||
card = await build_og_card(
|
||||
share_data.poster_url,
|
||||
prj_settings.SHARE_DEFAULT_IMAGE_URL,
|
||||
)
|
||||
return Response(
|
||||
content=card,
|
||||
media_type="image/jpeg",
|
||||
headers={
|
||||
"Cache-Control": "public, max-age=86400",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/{content_id}",
|
||||
response_model=SsulDetailResponse,
|
||||
|
||||
Reference in new issue
Block a user