feat(ssulbox): 상세·공유 화면과 좋아요·댓글·업로드 연동
This commit is contained in:
1 parent
7b1e691715
commit
741539a023
12 files changed
+836
-293
No files matched your search
+94
-58
@@ -34,6 +34,7 @@ import {
|
||||
VideoDetailItem,
|
||||
CommentsResponse,
|
||||
CommentItem,
|
||||
ContentType,
|
||||
LikeToggleResponse,
|
||||
} from '../types/api';
|
||||
|
||||
@@ -574,7 +575,7 @@ export async function getAllVideos(
|
||||
if (region.trim()) params.set('region', region.trim());
|
||||
const response = await authenticatedFetch(`${API_URL}/video/all?${params.toString()}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
}, { redirectOnAuthFail: false });
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
@@ -587,7 +588,7 @@ export async function getAllVideos(
|
||||
export async function getVideoById(videoId: string): Promise<VideoDetailItem> {
|
||||
const response = await authenticatedFetch(`${API_URL}/video/${videoId}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
}, { redirectOnAuthFail: false });
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
@@ -596,22 +597,75 @@ export async function getVideoById(videoId: string): Promise<VideoDetailItem> {
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// 댓글 목록 조회
|
||||
export async function getVideoComments(videoId: string, page: number = 1, pageSize: number = 20): Promise<CommentsResponse> {
|
||||
const response = await authenticatedFetch(`${API_URL}/comment/video/${videoId}?page=${page}&page_size=${pageSize}`, {
|
||||
// 썰박스 콘텐츠 공개 상세 (비로그인 허용 — 공유 링크 /ssul/{id} 가 사용)
|
||||
export interface SsulDetailItem {
|
||||
content_id: number;
|
||||
scenario: string;
|
||||
video_url: string;
|
||||
store_name: string | null;
|
||||
region: string | null;
|
||||
created_at: string;
|
||||
like_count: number;
|
||||
is_liked_by_me: boolean;
|
||||
}
|
||||
|
||||
export async function getSsulContentById(contentId: string): Promise<SsulDetailItem> {
|
||||
const response = await authenticatedFetch(`${API_URL}/ssul/${contentId}`, {
|
||||
method: 'GET',
|
||||
}, { redirectOnAuthFail: false });
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// 썰박스 콘텐츠 소프트 삭제.
|
||||
// ⚠️ deleteVideo(= /archive/videos/{id}, Video.id 기준)와 절대 혼용하지 말 것 —
|
||||
// id 가 겹치므로 엉뚱한 ADO2 영상이 지워진다. 썰박스는 반드시 이 함수로.
|
||||
export async function deleteSsulContent(contentId: number): Promise<void> {
|
||||
const response = await authenticatedFetch(`${API_URL}/ssul/${contentId}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 댓글 목록 조회
|
||||
// contentType: video.id 와 ssul_content.id 가 겹치므로 종류를 함께 보낸다 (기본 'video')
|
||||
export async function getVideoComments(
|
||||
videoId: string,
|
||||
page: number = 1,
|
||||
pageSize: number = 20,
|
||||
contentType: ContentType = 'video'
|
||||
): Promise<CommentsResponse> {
|
||||
const response = await authenticatedFetch(
|
||||
`${API_URL}/comment/video/${videoId}?page=${page}&page_size=${pageSize}&type=${contentType}`,
|
||||
{
|
||||
method: 'GET',
|
||||
},
|
||||
{ redirectOnAuthFail: false }
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// 댓글 작성
|
||||
export async function postVideoComment(videoId: string, content: string, nickname?: string, parentId?: number): Promise<CommentItem> {
|
||||
const response = await authenticatedFetch(`${API_URL}/comment/video/${videoId}`, {
|
||||
export async function postVideoComment(
|
||||
videoId: string,
|
||||
content: string,
|
||||
nickname?: string,
|
||||
parentId?: number,
|
||||
contentType: ContentType = 'video'
|
||||
): Promise<CommentItem> {
|
||||
const response = await authenticatedFetch(`${API_URL}/comment/video/${videoId}?type=${contentType}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ content, nickname: nickname || '익명', parent_id: parentId ?? null }),
|
||||
@@ -636,10 +690,18 @@ export async function deleteComment(commentId: number): Promise<void> {
|
||||
}
|
||||
|
||||
// 좋아요 토글
|
||||
export async function toggleVideoLike(videoId: string): Promise<LikeToggleResponse> {
|
||||
const response = await authenticatedFetch(`${API_URL}/video/${videoId}/like`, {
|
||||
method: 'POST',
|
||||
});
|
||||
export async function toggleVideoLike(
|
||||
videoId: string,
|
||||
// video.id 와 ssul_content.id 가 겹치므로 종류를 함께 보내야 한다.
|
||||
// 기본값 'video' 라 기존 호출부는 수정이 없다.
|
||||
contentType: ContentType = 'video'
|
||||
): Promise<LikeToggleResponse> {
|
||||
const response = await authenticatedFetch(
|
||||
`${API_URL}/video/${videoId}/like?type=${contentType}`,
|
||||
{
|
||||
method: 'POST',
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
@@ -786,7 +848,8 @@ function redirectToLogin() {
|
||||
// 401 에러 시 자동으로 토큰 갱신 후 재요청하는 래퍼 함수
|
||||
export async function authenticatedFetch(
|
||||
url: string,
|
||||
options: RequestInit = {}
|
||||
options: RequestInit = {},
|
||||
{ redirectOnAuthFail = true }: { redirectOnAuthFail?: boolean } = {}
|
||||
): Promise<Response> {
|
||||
// 인증 헤더 + 캐시 방지 헤더 추가
|
||||
const headers: HeadersInit = {
|
||||
@@ -803,9 +866,14 @@ export async function authenticatedFetch(
|
||||
const errorBody = await response.json().catch(() => null);
|
||||
const errorCode = errorBody?.detail?.code;
|
||||
|
||||
// 애초에 토큰이 없던 익명 요청(공개 화면)까지 튕기면 안 되므로 별도 처리
|
||||
const isMissingToken = errorCode === 'MISSING_TOKEN';
|
||||
|
||||
if (errorCode !== 'TOKEN_EXPIRED') {
|
||||
// INVALID_TOKEN 등 갱신으로 해결 불가한 경우 즉시 로그인 이동
|
||||
redirectToLogin();
|
||||
if (redirectOnAuthFail && !isMissingToken) {
|
||||
redirectToLogin();
|
||||
}
|
||||
throw new Error(errorCode ?? 'Unauthorized');
|
||||
}
|
||||
|
||||
@@ -828,7 +896,9 @@ export async function authenticatedFetch(
|
||||
response = await fetch(url, { ...options, headers: newHeaders });
|
||||
} catch (refreshError) {
|
||||
console.error('Token refresh failed:', refreshError);
|
||||
redirectToLogin();
|
||||
if (redirectOnAuthFail) {
|
||||
redirectToLogin();
|
||||
}
|
||||
throw refreshError;
|
||||
}
|
||||
}
|
||||
@@ -1331,34 +1401,19 @@ export async function retryUpload(uploadId: number): Promise<{ success: boolean;
|
||||
// 썰박스 (Ssulbox)
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 썰박스 장소 검색 결과.
|
||||
*
|
||||
* castad `/search/accommodation`(네이버 검색 API)과 달리 **`place_url` 을 준다.**
|
||||
* generator 가 네이버 지도 place 페이지를 크롤링하므로 이 URL 이 반드시 필요해서
|
||||
* 별도 엔드포인트를 쓴다.
|
||||
*/
|
||||
export interface SsulPlaceItem {
|
||||
title: string;
|
||||
category: string;
|
||||
address: string;
|
||||
roadAddress: string;
|
||||
place_url: string;
|
||||
}
|
||||
|
||||
export interface SsulCreateRequest {
|
||||
scenario: string;
|
||||
/** 네이버 지도 place URL 또는 업장명 */
|
||||
/**
|
||||
* 업장명 또는 네이버 지도 링크.
|
||||
*
|
||||
* 자동완성으로 고른 경우 **업장명**을 보낸다 — place URL 해석은 서버가
|
||||
* ADO2 와 동일한 경로(NvMapPwScraper)로 처리한다. 링크를 직접 붙여넣었으면
|
||||
* 그대로 보낸다.
|
||||
*/
|
||||
input: string;
|
||||
scenes?: number;
|
||||
seconds?: number;
|
||||
/**
|
||||
* 검색으로 업장을 고른 경우에만 함께 보낸다.
|
||||
*
|
||||
* 통합 콘텐츠 목록의 업장명 표시와 `store_name`/`region` 필터가 이 값에 의존한다.
|
||||
* 링크를 직접 붙여넣은 경우에는 보낼 값이 없고, 그때 업장명은 백엔드가 생성
|
||||
* 로그에서 뒤늦게 채운다(주소가 없어 지역은 채우지 못한다).
|
||||
*/
|
||||
/** 자동완성으로 고른 경우에만. 목록 표시·필터·place URL 해석에 쓰인다 */
|
||||
store_name?: string;
|
||||
/** 지역 추출용(도로명). 백엔드는 이 값을 저장하지 않는다 */
|
||||
road_address?: string;
|
||||
@@ -1369,29 +1424,9 @@ export interface SsulCreateRequest {
|
||||
export interface SsulCreateResponse {
|
||||
id: number;
|
||||
status: string;
|
||||
poll_interval_seconds?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 업장 검색. 실패해도 빈 배열을 돌려준다 —
|
||||
* 사용자는 네이버 링크를 직접 붙여넣는 우회 경로가 있으므로 흐름을 막지 않는다.
|
||||
*/
|
||||
export async function searchSsulPlace(query: string): Promise<SsulPlaceItem[]> {
|
||||
try {
|
||||
const response = await authenticatedFetch(
|
||||
`${API_URL}/ssul/search/place?query=${encodeURIComponent(query)}`
|
||||
);
|
||||
if (!response.ok) return [];
|
||||
const data = await response.json();
|
||||
return data.items ?? [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 썰박스 생성 요청. **요청 시점에 크레딧이 선차감된다.**
|
||||
* 잔액이 부족하면 402 를 던지므로 호출부가 충전 화면으로 유도해야 한다.
|
||||
*/
|
||||
export async function createSsulJob(
|
||||
request: SsulCreateRequest
|
||||
): Promise<SsulCreateResponse> {
|
||||
@@ -1426,6 +1461,7 @@ export interface SsulTaskStatus {
|
||||
step: number;
|
||||
error: string | null;
|
||||
video_url: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
/** 폴링 간격. castad 의 waitForVideoComplete 와 동일하게 맞춘다 */
|
||||
|
||||
Reference in new issue
Block a user