인디케이터 추가 및 css코드 분리
This commit is contained in:
1 parent
429c8d4708
commit
888ac4fa5e
45 files changed
+13009
-14040
No files matched your search
@@ -1,7 +1,7 @@
|
||||
|
||||
import React, { useState, useRef, useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { generateLyric, waitForLyricComplete, generateSong, waitForSongComplete } from '../../utils/api';
|
||||
import { generateLyric, waitForLyricComplete, generateSong, waitForSongComplete, downloadSong } from '../../utils/api';
|
||||
import { LANGUAGE_MAP } from '../../types/api';
|
||||
|
||||
interface BusinessInfo {
|
||||
@@ -16,6 +16,7 @@ interface SoundStudioContentProps {
|
||||
businessInfo?: BusinessInfo;
|
||||
imageTaskId: string | null;
|
||||
mId: number;
|
||||
bizType?: string;
|
||||
onStatusChange?: (status: string) => void;
|
||||
videoGenerationStatus?: 'idle' | 'generating' | 'complete' | 'error';
|
||||
videoGenerationProgress?: number;
|
||||
@@ -26,6 +27,10 @@ type GenerationStatus = 'idle' | 'generating_lyric' | 'generating_song' | 'polli
|
||||
|
||||
const MAX_RETRY_COUNT = 3;
|
||||
|
||||
// 생성 완료된 곡 상태를 새로고침 후에도 복원하기 위한 키
|
||||
// GenerationFlow의 clearAllProjectStorage가 이 키를 포함해 정리함
|
||||
const SONG_GENERATION_KEY = 'castad_song_generation';
|
||||
|
||||
const sanitizeError = (message: string, fallback: string): string => {
|
||||
if (
|
||||
message.includes('Traceback') ||
|
||||
@@ -54,6 +59,7 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
|
||||
businessInfo,
|
||||
imageTaskId,
|
||||
mId,
|
||||
bizType = 'place',
|
||||
onStatusChange,
|
||||
videoGenerationStatus = 'idle',
|
||||
videoGenerationProgress = 0,
|
||||
@@ -89,6 +95,41 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
|
||||
localStorage.setItem('castad_song_completion', JSON.stringify(completionData));
|
||||
};
|
||||
|
||||
// 새로고침 후 생성 완료된 곡 상태 복원
|
||||
useEffect(() => {
|
||||
const saved = localStorage.getItem(SONG_GENERATION_KEY);
|
||||
if (!saved) return;
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(saved);
|
||||
if (parsed.status !== 'complete' || !parsed.audioUrl || !parsed.songTaskId) return;
|
||||
|
||||
// 저장된 URL로 일단 복원 후, 서버에서 최신 URL 재조회 시도
|
||||
setSongTaskId(parsed.songTaskId);
|
||||
setAudioUrl(parsed.audioUrl);
|
||||
setLyrics(parsed.lyrics ?? '');
|
||||
setStatus('complete');
|
||||
|
||||
// downloadSong으로 최신 URL을 재조회해 갱신 (만료 방지)
|
||||
downloadSong(parsed.songTaskId)
|
||||
.then((res) => {
|
||||
if (res.success && res.song_result_url) {
|
||||
setAudioUrl(res.song_result_url);
|
||||
// 저장값도 갱신
|
||||
localStorage.setItem(SONG_GENERATION_KEY, JSON.stringify({
|
||||
...parsed,
|
||||
audioUrl: res.song_result_url,
|
||||
}));
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
// 재조회 실패 시 저장된 URL 그대로 사용
|
||||
});
|
||||
} catch {
|
||||
// 파싱 실패 시 무시
|
||||
}
|
||||
}, []); // 마운트 1회만 실행
|
||||
|
||||
// Close language dropdown when clicking outside
|
||||
// Auto-navigate to next page when video generation is complete
|
||||
useEffect(() => {
|
||||
@@ -128,6 +169,18 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
|
||||
setStatusMessage('');
|
||||
setRetryCount(0);
|
||||
|
||||
// 새로고침 후에도 복원할 수 있도록 완료된 곡 상태를 저장
|
||||
try {
|
||||
localStorage.setItem(SONG_GENERATION_KEY, JSON.stringify({
|
||||
audioUrl: statusResponse.song_result_url,
|
||||
songTaskId: taskId,
|
||||
lyrics: currentLyrics,
|
||||
status: 'complete',
|
||||
}));
|
||||
} catch {
|
||||
// localStorage 쓰기 실패는 무시
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Polling failed:', error);
|
||||
|
||||
@@ -286,6 +339,9 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
|
||||
return;
|
||||
}
|
||||
|
||||
// 새 곡 생성 시작 — 이전에 저장된 완료 곡 제거
|
||||
localStorage.removeItem(SONG_GENERATION_KEY);
|
||||
|
||||
setStatus('generating_lyric');
|
||||
setErrorMessage(null);
|
||||
setStatusMessage(t('soundStudio.generatingLyrics'));
|
||||
@@ -306,6 +362,7 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
|
||||
m_id: mId,
|
||||
region: businessInfo.region,
|
||||
task_id: imageTaskId,
|
||||
biz_type: bizType,
|
||||
orientation,
|
||||
...(isInstrumental && { instrumental: true }),
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user