자동완성 버그 픽스 .
This commit is contained in:
1 parent
6d89a28982
commit
e997b2b5af
6 files changed
+319
-76
No files matched your search
+66
-55
@@ -59,11 +59,10 @@ export async function crawlUrl(url: string): Promise<CrawlingResponse> {
|
||||
|
||||
// 가사 생성 API
|
||||
export async function generateLyric(request: LyricGenerateRequest): Promise<LyricGenerateResponse> {
|
||||
const response = await fetch(`${API_URL}/lyric/generate`, {
|
||||
const response = await authenticatedFetch(`${API_URL}/lyric/generate`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...getAuthHeader(),
|
||||
},
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
@@ -77,11 +76,8 @@ export async function generateLyric(request: LyricGenerateRequest): Promise<Lyri
|
||||
|
||||
// 가사 상태 조회 API
|
||||
export async function getLyricStatus(taskId: string): Promise<LyricStatusResponse> {
|
||||
const response = await fetch(`${API_URL}/lyric/status/${taskId}`, {
|
||||
const response = await authenticatedFetch(`${API_URL}/lyric/status/${taskId}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
...getAuthHeader(),
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -93,11 +89,8 @@ export async function getLyricStatus(taskId: string): Promise<LyricStatusRespons
|
||||
|
||||
// 가사 상세 조회 API
|
||||
export async function getLyricDetail(taskId: string): Promise<LyricDetailResponse> {
|
||||
const response = await fetch(`${API_URL}/lyric/${taskId}`, {
|
||||
const response = await authenticatedFetch(`${API_URL}/lyric/${taskId}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
...getAuthHeader(),
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -149,11 +142,10 @@ export async function waitForLyricComplete(
|
||||
|
||||
// 노래 생성 API (task_id는 URL 경로에 포함)
|
||||
export async function generateSong(taskId: string, request: SongGenerateRequest): Promise<SongGenerateResponse> {
|
||||
const response = await fetch(`${API_URL}/song/generate/${taskId}`, {
|
||||
const response = await authenticatedFetch(`${API_URL}/song/generate/${taskId}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...getAuthHeader(),
|
||||
},
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
@@ -167,11 +159,8 @@ export async function generateSong(taskId: string, request: SongGenerateRequest)
|
||||
|
||||
// 노래 상태 조회 API (Suno Polling)
|
||||
export async function getSongStatus(songId: string): Promise<SongStatusResponse> {
|
||||
const response = await fetch(`${API_URL}/song/status/${songId}`, {
|
||||
const response = await authenticatedFetch(`${API_URL}/song/status/${songId}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
...getAuthHeader(),
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -183,11 +172,8 @@ export async function getSongStatus(songId: string): Promise<SongStatusResponse>
|
||||
|
||||
// 노래 다운로드 API
|
||||
export async function downloadSong(taskId: string): Promise<SongDownloadResponse> {
|
||||
const response = await fetch(`${API_URL}/song/download/${taskId}`, {
|
||||
const response = await authenticatedFetch(`${API_URL}/song/download/${taskId}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
...getAuthHeader(),
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -248,11 +234,8 @@ export async function waitForSongComplete(
|
||||
|
||||
// 영상 생성 API
|
||||
export async function generateVideo(taskId: string, orientation: 'vertical' | 'horizontal' = 'vertical'): Promise<VideoGenerateResponse> {
|
||||
const response = await fetch(`${API_URL}/video/generate/${taskId}?orientation=${orientation}`, {
|
||||
const response = await authenticatedFetch(`${API_URL}/video/generate/${taskId}?orientation=${orientation}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
...getAuthHeader(),
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -264,11 +247,8 @@ export async function generateVideo(taskId: string, orientation: 'vertical' | 'h
|
||||
|
||||
// 영상 상태 확인 API
|
||||
export async function getVideoStatus(taskId: string): Promise<VideoStatusResponse> {
|
||||
const response = await fetch(`${API_URL}/video/status/${taskId}`, {
|
||||
const response = await authenticatedFetch(`${API_URL}/video/status/${taskId}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
...getAuthHeader(),
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -296,10 +276,11 @@ export async function getVideoStatus(taskId: string): Promise<VideoStatusRespons
|
||||
|
||||
// 비디오 목록 조회 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}`, {
|
||||
const response = await authenticatedFetch(`${API_URL}/archive/videos/?page=${page}&page_size=${pageSize}&_t=${Date.now()}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
...getAuthHeader(),
|
||||
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
||||
'Pragma': 'no-cache',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -312,11 +293,8 @@ export async function getVideosList(page: number = 1, pageSize: number = 10): Pr
|
||||
|
||||
// 비디오 삭제 API
|
||||
export async function deleteVideo(taskId: string): Promise<void> {
|
||||
const response = await fetch(`${API_URL}/archive/videos/delete/${taskId}`, {
|
||||
const response = await authenticatedFetch(`${API_URL}/archive/videos/delete/${taskId}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
...getAuthHeader(),
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -348,11 +326,8 @@ export async function uploadImages(
|
||||
const timeoutId = setTimeout(() => controller.abort(), IMAGE_UPLOAD_TIMEOUT);
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_URL}/image/upload/blob`, {
|
||||
const response = await authenticatedFetch(`${API_URL}/image/upload/blob`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...getAuthHeader(),
|
||||
},
|
||||
body: formData,
|
||||
signal: controller.signal,
|
||||
});
|
||||
@@ -449,6 +424,54 @@ function getAuthHeader(): HeadersInit {
|
||||
return token ? { 'Authorization': `Bearer ${token}` } : {};
|
||||
}
|
||||
|
||||
// 토큰 갱신 중복 방지를 위한 플래그
|
||||
let isRefreshing = false;
|
||||
let refreshPromise: Promise<TokenRefreshResponse> | null = null;
|
||||
|
||||
// 401 에러 시 자동으로 토큰 갱신 후 재요청하는 래퍼 함수
|
||||
async function authenticatedFetch(
|
||||
url: string,
|
||||
options: RequestInit = {}
|
||||
): Promise<Response> {
|
||||
// 인증 헤더 추가
|
||||
const headers = {
|
||||
...options.headers,
|
||||
...getAuthHeader(),
|
||||
};
|
||||
|
||||
let response = await fetch(url, { ...options, headers });
|
||||
|
||||
// 401 에러 시 토큰 갱신 시도
|
||||
if (response.status === 401) {
|
||||
try {
|
||||
// 이미 갱신 중이면 기존 Promise 재사용 (중복 요청 방지)
|
||||
if (!isRefreshing) {
|
||||
isRefreshing = true;
|
||||
refreshPromise = refreshAccessToken();
|
||||
}
|
||||
|
||||
await refreshPromise;
|
||||
isRefreshing = false;
|
||||
refreshPromise = null;
|
||||
|
||||
// 새 토큰으로 재요청
|
||||
const newHeaders = {
|
||||
...options.headers,
|
||||
...getAuthHeader(),
|
||||
};
|
||||
response = await fetch(url, { ...options, headers: newHeaders });
|
||||
} catch (refreshError) {
|
||||
isRefreshing = false;
|
||||
refreshPromise = null;
|
||||
// 토큰 갱신 실패 시 로그인 페이지로 리다이렉트할 수 있음
|
||||
console.error('Token refresh failed:', refreshError);
|
||||
throw refreshError;
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
// 카카오 로그인 URL 획득
|
||||
export async function getKakaoLoginUrl(): Promise<KakaoLoginUrlResponse> {
|
||||
const response = await fetch(`${API_URL}/user/auth/kakao/login`, {
|
||||
@@ -533,11 +556,8 @@ export async function refreshAccessToken(): Promise<TokenRefreshResponse> {
|
||||
|
||||
// 로그아웃
|
||||
export async function logout(): Promise<void> {
|
||||
const response = await fetch(`${API_URL}/user/auth/logout`, {
|
||||
const response = await authenticatedFetch(`${API_URL}/user/auth/logout`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...getAuthHeader(),
|
||||
},
|
||||
});
|
||||
|
||||
// 응답과 관계없이 로컬 토큰 삭제
|
||||
@@ -550,11 +570,8 @@ export async function logout(): Promise<void> {
|
||||
|
||||
// 모든 기기에서 로그아웃
|
||||
export async function logoutAll(): Promise<void> {
|
||||
const response = await fetch(`${API_URL}/user/auth/logout/all`, {
|
||||
const response = await authenticatedFetch(`${API_URL}/user/auth/logout/all`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...getAuthHeader(),
|
||||
},
|
||||
});
|
||||
|
||||
// 응답과 관계없이 로컬 토큰 삭제
|
||||
@@ -567,11 +584,8 @@ export async function logoutAll(): Promise<void> {
|
||||
|
||||
// 현재 사용자 정보 조회
|
||||
export async function getUserMe(): Promise<UserMeResponse> {
|
||||
const response = await fetch(`${API_URL}/user/auth/me`, {
|
||||
const response = await authenticatedFetch(`${API_URL}/user/auth/me`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
...getAuthHeader(),
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -610,11 +624,8 @@ export interface AutocompleteRequest {
|
||||
|
||||
// 숙소 검색 API (업체명 자동완성용)
|
||||
export async function searchAccommodation(query: string): Promise<AccommodationSearchResponse> {
|
||||
const response = await fetch(`${API_URL}/search/accommodation?query=${encodeURIComponent(query)}`, {
|
||||
const response = await authenticatedFetch(`${API_URL}/search/accommodation?query=${encodeURIComponent(query)}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
...getAuthHeader(),
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -630,7 +641,7 @@ export async function autocomplete(request: AutocompleteRequest): Promise<Crawli
|
||||
const timeoutId = setTimeout(() => controller.abort(), CRAWL_TIMEOUT);
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_URL}/autocomplete`, {
|
||||
const response = await authenticatedFetch(`${API_URL}/autocomplete`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
Reference in new issue
Block a user