브랜드 분석 페이지 수정, ado2 컨텐츠 추가, header jwt 인증 작업 .

This commit is contained in:
HyeongBaeYang committed 2026-01-29 13:27:33 +09:00
1 parent 7d4f3c7e05
commit 7ee911f0aa
7 files changed
+865 -139

No files matched your search

+155 -13
View File
@@ -21,6 +21,8 @@ import {
} from '../types/api';
const API_URL = import.meta.env.VITE_API_URL || 'http://40.82.133.44';
console.log('[API] API_URL:', API_URL);
console.log('[API] VITE_API_URL env:', import.meta.env.VITE_API_URL);
// 크롤링 타임아웃: 5분
const CRAWL_TIMEOUT = 5 * 60 * 1000;
@@ -61,6 +63,7 @@ export async function generateLyric(request: LyricGenerateRequest): Promise<Lyri
method: 'POST',
headers: {
'Content-Type': 'application/json',
...getAuthHeader(),
},
body: JSON.stringify(request),
});
@@ -76,6 +79,9 @@ export async function generateLyric(request: LyricGenerateRequest): Promise<Lyri
export async function getLyricStatus(taskId: string): Promise<LyricStatusResponse> {
const response = await fetch(`${API_URL}/lyric/status/${taskId}`, {
method: 'GET',
headers: {
...getAuthHeader(),
},
});
if (!response.ok) {
@@ -89,6 +95,9 @@ export async function getLyricStatus(taskId: string): Promise<LyricStatusRespons
export async function getLyricDetail(taskId: string): Promise<LyricDetailResponse> {
const response = await fetch(`${API_URL}/lyric/${taskId}`, {
method: 'GET',
headers: {
...getAuthHeader(),
},
});
if (!response.ok) {
@@ -144,6 +153,7 @@ export async function generateSong(taskId: string, request: SongGenerateRequest)
method: 'POST',
headers: {
'Content-Type': 'application/json',
...getAuthHeader(),
},
body: JSON.stringify(request),
});
@@ -159,6 +169,9 @@ export async function generateSong(taskId: string, request: SongGenerateRequest)
export async function getSongStatus(songId: string): Promise<SongStatusResponse> {
const response = await fetch(`${API_URL}/song/status/${songId}`, {
method: 'GET',
headers: {
...getAuthHeader(),
},
});
if (!response.ok) {
@@ -172,6 +185,9 @@ export async function getSongStatus(songId: string): Promise<SongStatusResponse>
export async function downloadSong(taskId: string): Promise<SongDownloadResponse> {
const response = await fetch(`${API_URL}/song/download/${taskId}`, {
method: 'GET',
headers: {
...getAuthHeader(),
},
});
if (!response.ok) {
@@ -234,6 +250,9 @@ export async function waitForSongComplete(
export async function generateVideo(taskId: string, orientation: 'vertical' | 'horizontal' = 'vertical'): Promise<VideoGenerateResponse> {
const response = await fetch(`${API_URL}/video/generate/${taskId}?orientation=${orientation}`, {
method: 'GET',
headers: {
...getAuthHeader(),
},
});
if (!response.ok) {
@@ -247,6 +266,9 @@ export async function generateVideo(taskId: string, orientation: 'vertical' | 'h
export async function getVideoStatus(taskId: string): Promise<VideoStatusResponse> {
const response = await fetch(`${API_URL}/video/status/${taskId}`, {
method: 'GET',
headers: {
...getAuthHeader(),
},
});
if (!response.ok) {
@@ -257,9 +279,28 @@ export async function getVideoStatus(taskId: string): Promise<VideoStatusRespons
}
// 영상 다운로드(결과 조회) API
export async function downloadVideo(taskId: string): Promise<VideoDownloadResponse> {
const response = await fetch(`${API_URL}/video/download/${taskId}`, {
// export async function downloadVideo(taskId: string): Promise<VideoDownloadResponse> {
// const response = await fetch(`${API_URL}/video/download/${taskId}`, {
// method: 'GET',
// headers: {
// ...getAuthHeader(),
// },
// });
// if (!response.ok) {
// throw new Error(`HTTP error! status: ${response.status}`);
// }
// return response.json();
// }
// 비디오 목록 조회 API
export async function getVideosList(page: number = 1, pageSize: number = 10): Promise<VideosListResponse> {
const response = await fetch(`${API_URL}/archive/videos/?page=${page}&page_size=${pageSize}`, {
method: 'GET',
headers: {
...getAuthHeader(),
},
});
if (!response.ok) {
@@ -269,17 +310,18 @@ export async function downloadVideo(taskId: string): Promise<VideoDownloadRespon
return response.json();
}
// 비디오 목록 조회 API
export async function getVideosList(page: number = 1, pageSize: number = 10): Promise<VideosListResponse> {
const response = await fetch(`${API_URL}/videos/?page=${page}&page_size=${pageSize}`, {
method: 'GET',
// 비디오 삭제 API
export async function deleteVideo(taskId: string): Promise<void> {
const response = await fetch(`${API_URL}/archive/videos/delete/${taskId}`, {
method: 'DELETE',
headers: {
...getAuthHeader(),
},
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
}
// 이미지 업로드 API (multipart/form-data)
@@ -308,6 +350,9 @@ export async function uploadImages(
try {
const response = await fetch(`${API_URL}/image/upload/blob`, {
method: 'POST',
headers: {
...getAuthHeader(),
},
body: formData,
signal: controller.signal,
});
@@ -401,6 +446,7 @@ export function clearTokens() {
// 인증 헤더 생성
function getAuthHeader(): HeadersInit {
const token = getAccessToken();
console.log('[Auth] Token exists:', !!token, token ? `${token.substring(0, 20)}...` : 'null');
return token ? { 'Authorization': `Bearer ${token}` } : {};
}
@@ -418,20 +464,39 @@ export async function getKakaoLoginUrl(): Promise<KakaoLoginUrlResponse> {
}
// 카카오 콜백 처리 (인가 코드로 JWT 토큰 발급)
// 1. callback 호출 후 2. verify로 토큰 발급
export async function kakaoCallback(code: string): Promise<KakaoCallbackResponse> {
const response = await fetch(`${API_URL}/user/auth/kakao/callback?code=${encodeURIComponent(code)}`, {
// 1단계: 콜백 처리
const callbackResponse = await fetch(`${API_URL}/user/auth/kakao/callback?code=${encodeURIComponent(code)}`, {
method: 'GET',
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
if (!callbackResponse.ok) {
throw new Error(`Callback HTTP error! status: ${callbackResponse.status}`);
}
const data: KakaoCallbackResponse = await response.json();
// 2단계: 코드 검증 및 토큰 발급
const verifyResponse = await fetch(`${API_URL}/user/auth/kakao/verify`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ code }),
});
if (!verifyResponse.ok) {
throw new Error(`Verify HTTP error! status: ${verifyResponse.status}`);
}
const data: KakaoCallbackResponse = await verifyResponse.json();
console.log('[Auth] Kakao verify response:', {
hasAccessToken: !!data.access_token,
hasRefreshToken: !!data.refresh_token
});
// 토큰 저장
saveTokens(data.access_token, data.refresh_token);
console.log('[Auth] Tokens saved to localStorage');
return data;
}
@@ -525,3 +590,80 @@ export async function getUserMe(): Promise<UserMeResponse> {
export function isLoggedIn(): boolean {
return !!getAccessToken();
}
// ============================================
// 네이버 지역 검색 & 자동완성 API
// ============================================
export interface NaverLocalSearchItem {
title: string;
link: string;
category: string;
description: string;
telephone: string;
address: string;
roadAddress: string;
mapx: string;
mapy: string;
}
export interface NaverLocalSearchResponse {
lastBuildDate: string;
total: number;
start: number;
display: number;
items: NaverLocalSearchItem[];
}
export interface AutocompleteRequest {
address: string;
roadAddress: string;
title: string;
}
// 네이버 지역 검색 API (백엔드 프록시 경유)
export async function searchNaverLocal(query: string): Promise<NaverLocalSearchResponse> {
const response = await fetch(`${API_URL}/naver/local/search?query=${encodeURIComponent(query)}`, {
method: 'GET',
headers: {
...getAuthHeader(),
},
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
}
// 자동완성 API (업체 정보로 크롤링)
export async function autocomplete(request: AutocompleteRequest): Promise<CrawlingResponse> {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), CRAWL_TIMEOUT);
try {
const response = await fetch(`${API_URL}/autocomplete`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(request),
signal: controller.signal,
});
clearTimeout(timeoutId);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
} catch (error) {
clearTimeout(timeoutId);
if (error instanceof Error && error.name === 'AbortError') {
throw new Error('자동완성 요청 시간이 초과되었습니다. 다시 시도해주세요.');
}
throw error;
}
}