브랜드 분석 페이지 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

+4 -4
View File
@@ -314,16 +314,16 @@ const GenerationFlow: React.FC<GenerationFlowProps> = ({
// 스크롤이 필요한 페이지: 대시보드, 비즈니스 설정, 브랜드 분석(0)
const needsScroll = activeItem === '대시보드' || activeItem === '비즈니스 설정' || isBrandAnalysis;
// 브랜드 분석일 때는 높이 제한 없이 자연 스크롤
// 브랜드 분석일 때는 전체 화면 스크롤
if (isBrandAnalysis) {
return (
<div className="flex w-full bg-[#0d1416] text-white">
<div className="analysis-page-wrapper">
{showSidebar && (
<Sidebar activeItem={activeItem} onNavigate={setActiveItem} onHome={handleHome} />
)}
<div className="flex-1 relative">
<main className="analysis-page-main">
{renderContent()}
</div>
</main>
</div>
);
}
+16 -14
View File
@@ -22,6 +22,7 @@ type GenerationStatus = 'idle' | 'generating_lyric' | 'generating_song' | 'polli
interface SavedGenerationState {
taskId: string;
songId: string;
lyrics: string;
status: GenerationStatus;
timestamp: number;
@@ -70,9 +71,10 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
const audioRef = useRef<HTMLAudioElement>(null);
const languageDropdownRef = useRef<HTMLDivElement>(null);
const saveToStorage = (taskId: string, currentLyrics: string, currentStatus: GenerationStatus) => {
const saveToStorage = (taskId: string, songId: string, currentLyrics: string, currentStatus: GenerationStatus) => {
const data: SavedGenerationState = {
taskId,
songId,
lyrics: currentLyrics,
status: currentStatus,
timestamp: Date.now(),
@@ -112,7 +114,7 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
}
setStatus('polling');
setStatusMessage('노래를 생성하고 있습니다... (새로고침 후 복구됨)');
resumePolling(savedState.taskId, savedState.lyrics, 0);
resumePolling(savedState.taskId, savedState.songId, savedState.lyrics, 0);
}
}, []);
@@ -144,25 +146,25 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
}
}, [videoGenerationStatus, songTaskId, onNext]);
const resumePolling = async (taskId: string, currentLyrics: string, currentRetryCount: number = 0) => {
const resumePolling = async (taskId: string, songId: string, currentLyrics: string, currentRetryCount: number = 0) => {
try {
const downloadResponse = await waitForSongComplete(
taskId,
const statusResponse = await waitForSongComplete(
songId,
(pollStatus: string) => {
if (pollStatus === 'processing') {
if (pollStatus === 'streaming') {
setStatusMessage('노래를 생성하고 있습니다...');
} else if (pollStatus === 'uploading') {
setStatusMessage('노래를 업로드하고 있습니다...');
} else if (pollStatus === 'queued') {
setStatusMessage('노래 생성 대기 중...');
}
}
);
if (!downloadResponse.success) {
throw new Error(downloadResponse.error_message || '음악 다운로드에 실패했습니다.');
if (!statusResponse.success) {
throw new Error(statusResponse.error_message || '음악 생성에 실패했습니다.');
}
setAudioUrl(downloadResponse.song_result_url);
setSongTaskId(downloadResponse.task_id);
setAudioUrl(statusResponse.song_url);
setSongTaskId(taskId);
setStatus('complete');
setStatusMessage('');
setRetryCount(0);
@@ -218,8 +220,8 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
throw new Error(songResponse.error_message || '음악 생성 요청에 실패했습니다.');
}
saveToStorage(songResponse.task_id, currentLyrics, 'polling');
await resumePolling(songResponse.task_id, currentLyrics, currentRetryCount);
saveToStorage(songResponse.task_id, songResponse.song_id, currentLyrics, 'polling');
await resumePolling(songResponse.task_id, songResponse.song_id, currentLyrics, currentRetryCount);
} catch (error) {
console.error('Song regeneration failed:', error);
+9
View File
@@ -83,6 +83,15 @@ export interface SongGenerateResponse {
error_message: string | null;
}
// 노래 상태 조회 응답 (Suno Polling)
export interface SongStatusResponse {
success: boolean;
status: string;
message: string;
song_url: string | null;
error_message: string | null;
}
// 노래 다운로드 상태 조회 응답 (DB Polling)
export interface SongDownloadResponse {
success: boolean;
+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) {