브랜드 분석 페이지 css 수정, song id polling 적용 .

This commit is contained in:
HyeongBaeYang committed 2026-01-22 11:52:19 +09:00
1 parent e3ed840d12
commit d5b6ad6958
6 files changed
+120 -161

No files matched your search

+25 -17
View File
@@ -6,6 +6,7 @@ import {
LyricDetailResponse,
SongGenerateRequest,
SongGenerateResponse,
SongStatusResponse,
SongDownloadResponse,
VideoGenerateResponse,
VideoStatusResponse,
@@ -153,9 +154,21 @@ export async function generateSong(taskId: string, request: SongGenerateRequest)
return response.json();
}
// 노래 다운로드 상태 조회 API (DB Polling)
// task_id를 기반으로 Song 테이블의 상태를 조회하고, completed인 경우 Project 정보와 노래 URL을 반환
export async function getSongDownloadStatus(taskId: string): Promise<SongDownloadResponse> {
// 노래 상태 조회 API (Suno Polling)
export async function getSongStatus(songId: string): Promise<SongStatusResponse> {
const response = await fetch(`${API_URL}/song/status/${songId}`, {
method: 'GET',
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
}
// 노래 다운로드 API
export async function downloadSong(taskId: string): Promise<SongDownloadResponse> {
const response = await fetch(`${API_URL}/song/download/${taskId}`, {
method: 'GET',
});
@@ -168,42 +181,37 @@ export async function getSongDownloadStatus(taskId: string): Promise<SongDownloa
}
// 노래 생성 완료까지 폴링 (5분 타임아웃, 3초 간격)
// 새로운 API는 DB 상태를 직접 조회: processing, uploading, completed, failed, not_found, error
// Suno API 상태: PENDING, processing, SUCCESS, TEXT_SUCCESS, failed, error
const SONG_POLL_TIMEOUT = 5 * 60 * 1000; // 5분
const SONG_POLL_INTERVAL = 3000; // 3초
export async function waitForSongComplete(
taskId: string,
songId: string,
onStatusChange?: (status: string) => void
): Promise<SongDownloadResponse> {
): Promise<SongStatusResponse> {
const startTime = Date.now();
const poll = async (): Promise<SongDownloadResponse> => {
const poll = async (): Promise<SongStatusResponse> => {
// 5분 타임아웃 체크
if (Date.now() - startTime > SONG_POLL_TIMEOUT) {
throw new Error('TIMEOUT');
}
try {
const response = await getSongDownloadStatus(taskId);
const response = await getSongStatus(songId);
onStatusChange?.(response.status);
// completed: 모든 작업 완료, Blob URL 사용 가능
if (response.status === 'completed' && response.success) {
// SUCCESS 또는 TEXT_SUCCESS: Suno API 노래 생성 완료
if ((response.status === 'SUCCESS' || response.status === 'TEXT_SUCCESS') && response.success) {
return response;
}
// failed: 노래 생성 또는 업로드 실패
// failed 또는 error: Suno API 노래 생성 실패
if (response.status === 'failed' || response.status === 'error') {
throw new Error(response.error_message || '노래 생성에 실패했습니다.');
}
// not_found: task_id에 해당하는 Song 없음
if (response.status === 'not_found') {
throw new Error('노래를 찾을 수 없습니다.');
}
// processing, uploading 등은 대기 후 재시도
// PENDING, processing 등은 대기 후 재시도
await new Promise(resolve => setTimeout(resolve, SONG_POLL_INTERVAL));
return poll();
} catch (error) {