song/status 수정 .

This commit is contained in:
HyeongBaeYang committed 2026-01-26 12:00:52 +09:00
1 parent b6ece9891a
commit 5b2450ed60
3 files changed
+16 -52

No files matched your search

+11 -18
View File
@@ -8,7 +8,6 @@ import {
SongGenerateResponse,
SongStatusResponse,
SongDownloadResponse,
SongsListResponse,
VideoGenerateResponse,
VideoStatusResponse,
VideoDownloadResponse,
@@ -181,23 +180,11 @@ export async function downloadSong(taskId: string): Promise<SongDownloadResponse
return response.json();
}
// 노래 목록 조회 API
export async function getSongsList(page: number = 1, pageSize: number = 10): Promise<SongsListResponse> {
const response = await fetch(`${API_URL}/songs/?page=${page}&page_size=${pageSize}`, {
method: 'GET',
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
}
// 노래 생성 완료까지 폴링 (5분 타임아웃, 3초 간격)
// Suno API 상태: PENDING, processing, SUCCESS, TEXT_SUCCESS, failed, error
// Suno API 상태: PENDING, processing, SUCCESS, failed, error
const SONG_POLL_TIMEOUT = 5 * 60 * 1000; // 5분
const SONG_POLL_INTERVAL = 3000; // 3초
const SONG_URL_RETRY_DELAY = 4000; // SUCCESS인데 song_result_url 없을 때 재요청 대기 시간 (4초)
export async function waitForSongComplete(
songId: string,
@@ -215,9 +202,15 @@ export async function waitForSongComplete(
const response = await getSongStatus(songId);
onStatusChange?.(response.status);
// SUCCESS 또는 TEXT_SUCCESS: Suno API 노래 생성 완료
if ((response.status === 'SUCCESS' || response.status === 'TEXT_SUCCESS') && response.success) {
return response;
// SUCCESS: Suno API 노래 생성 완료
if (response.status === 'SUCCESS' && response.success) {
// song_result_url이 있으면 완료
if (response.song_result_url) {
return response;
}
// song_result_url이 없으면 4초 후 재요청
await new Promise(resolve => setTimeout(resolve, SONG_URL_RETRY_DELAY));
return poll();
}
// failed 또는 error: Suno API 노래 생성 실패