From 5b2450ed6022288fdeee744d8142ca36e495955d Mon Sep 17 00:00:00 2001 From: hbyang Date: Mon, 26 Jan 2026 12:00:52 +0900 Subject: [PATCH] =?UTF-8?q?song/status=20=EC=88=98=EC=A0=95=20.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Dashboard/SoundStudioContent.tsx | 17 +++---------- src/types/api.ts | 22 +--------------- src/utils/api.ts | 29 ++++++++-------------- 3 files changed, 16 insertions(+), 52 deletions(-) diff --git a/src/pages/Dashboard/SoundStudioContent.tsx b/src/pages/Dashboard/SoundStudioContent.tsx index 5740bed..fb44a1f 100755 --- a/src/pages/Dashboard/SoundStudioContent.tsx +++ b/src/pages/Dashboard/SoundStudioContent.tsx @@ -1,6 +1,6 @@ import React, { useState, useRef, useEffect } from 'react'; -import { generateLyric, waitForLyricComplete, generateSong, waitForSongComplete, getSongsList } from '../../utils/api'; +import { generateLyric, waitForLyricComplete, generateSong, waitForSongComplete } from '../../utils/api'; import { LANGUAGE_MAP } from '../../types/api'; interface BusinessInfo { @@ -105,18 +105,9 @@ const SoundStudioContent: React.FC = ({ throw new Error(statusResponse.error_message || '음악 생성에 실패했습니다.'); } - // 노래 생성 완료 후 songs 목록에서 최신 task_id와 song_result_url 가져오기 - const songsResponse = await getSongsList(1, 1); - if (songsResponse.items && songsResponse.items.length > 0) { - const latestSong = songsResponse.items[0]; - setSongTaskId(latestSong.task_id); - // song_result_url을 사용하여 재생 - setAudioUrl(latestSong.song_result_url); - } else { - // fallback: 기존 데이터 사용 - setSongTaskId(taskId); - setAudioUrl(statusResponse.song_url); - } + // song_result_url을 사용하여 재생 + setSongTaskId(taskId); + setAudioUrl(statusResponse.song_result_url); setStatus('complete'); setStatusMessage(''); diff --git a/src/types/api.ts b/src/types/api.ts index 1381215..6bcf50b 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -88,7 +88,7 @@ export interface SongStatusResponse { success: boolean; status: string; message: string; - song_url: string | null; + song_result_url: string | null; error_message: string | null; } @@ -214,23 +214,3 @@ export interface UserMeResponse { created_at: string; } -// 노래 목록 아이템 -export interface SongListItem { - store_name: string; - region: string; - task_id: string; - language: string; - song_result_url: string; - created_at: string; -} - -// 노래 목록 응답 -export interface SongsListResponse { - items: SongListItem[]; - total: number; - page: number; - page_size: number; - total_pages: number; - has_next: boolean; - has_prev: boolean; -} diff --git a/src/utils/api.ts b/src/utils/api.ts index eb52f0b..e4d246a 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -8,7 +8,6 @@ import { SongGenerateResponse, SongStatusResponse, SongDownloadResponse, - SongsListResponse, VideoGenerateResponse, VideoStatusResponse, VideoDownloadResponse, @@ -181,23 +180,11 @@ export async function downloadSong(taskId: string): Promise { - 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 노래 생성 실패