From 16ef7bd97d1ad4b6f0c50d5349828395fb49cd1d Mon Sep 17 00:00:00 2001 From: hbyang Date: Thu, 22 Jan 2026 13:31:18 +0900 Subject: [PATCH] =?UTF-8?q?local=20storage=20=EC=82=AD=EC=A0=9C=20.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Dashboard/SoundStudioContent.tsx | 68 ---------------------- 1 file changed, 68 deletions(-) diff --git a/src/pages/Dashboard/SoundStudioContent.tsx b/src/pages/Dashboard/SoundStudioContent.tsx index a51fd19..ac26b96 100755 --- a/src/pages/Dashboard/SoundStudioContent.tsx +++ b/src/pages/Dashboard/SoundStudioContent.tsx @@ -20,16 +20,6 @@ interface SoundStudioContentProps { type GenerationStatus = 'idle' | 'generating_lyric' | 'generating_song' | 'polling' | 'complete' | 'error'; -interface SavedGenerationState { - taskId: string; - songId: string; - lyrics: string; - status: GenerationStatus; - timestamp: number; -} - -const STORAGE_KEY = 'castad_song_generation'; -const STORAGE_EXPIRY = 30 * 60 * 1000; const MAX_RETRY_COUNT = 3; const LANGUAGE_FLAGS: Record = { @@ -55,7 +45,6 @@ const SoundStudioContent: React.FC = ({ const [progress, setProgress] = useState(0); const [isDragging, setIsDragging] = useState(false); const [status, setStatus] = useState('idle'); - const [showLyrics, setShowLyrics] = useState(false); const [lyrics, setLyrics] = useState(''); const [audioUrl, setAudioUrl] = useState(null); const [isPlaying, setIsPlaying] = useState(false); @@ -71,53 +60,6 @@ const SoundStudioContent: React.FC = ({ const audioRef = useRef(null); const languageDropdownRef = useRef(null); - const saveToStorage = (taskId: string, songId: string, currentLyrics: string, currentStatus: GenerationStatus) => { - const data: SavedGenerationState = { - taskId, - songId, - lyrics: currentLyrics, - status: currentStatus, - timestamp: Date.now(), - }; - localStorage.setItem(STORAGE_KEY, JSON.stringify(data)); - }; - - const clearStorage = () => { - localStorage.removeItem(STORAGE_KEY); - }; - - const loadFromStorage = (): SavedGenerationState | null => { - try { - const saved = localStorage.getItem(STORAGE_KEY); - if (!saved) return null; - - const data: SavedGenerationState = JSON.parse(saved); - - if (Date.now() - data.timestamp > STORAGE_EXPIRY) { - clearStorage(); - return null; - } - - return data; - } catch { - clearStorage(); - return null; - } - }; - - useEffect(() => { - const savedState = loadFromStorage(); - if (savedState && (savedState.status === 'polling' || savedState.status === 'generating_song')) { - if (savedState.lyrics) { - setLyrics(savedState.lyrics); - setShowLyrics(true); - } - setStatus('polling'); - setStatusMessage('노래를 생성하고 있습니다... (새로고침 후 복구됨)'); - resumePolling(savedState.taskId, savedState.songId, savedState.lyrics, 0); - } - }, []); - // Close language dropdown when clicking outside useEffect(() => { const handleClickOutside = (event: MouseEvent) => { @@ -168,7 +110,6 @@ const SoundStudioContent: React.FC = ({ setStatus('complete'); setStatusMessage(''); setRetryCount(0); - clearStorage(); } catch (error) { console.error('Polling failed:', error); @@ -183,13 +124,11 @@ const SoundStudioContent: React.FC = ({ setStatus('error'); setErrorMessage('여러 번 시도했지만 음악 생성에 실패했습니다. 다시 시도해주세요.'); setRetryCount(0); - clearStorage(); } } else { setStatus('error'); setErrorMessage(error instanceof Error ? error.message : '음악 생성 중 오류가 발생했습니다.'); setRetryCount(0); - clearStorage(); } } }; @@ -220,7 +159,6 @@ const SoundStudioContent: React.FC = ({ throw new Error(songResponse.error_message || '음악 생성 요청에 실패했습니다.'); } - saveToStorage(songResponse.task_id, songResponse.song_id, currentLyrics, 'polling'); await resumePolling(songResponse.task_id, songResponse.song_id, currentLyrics, currentRetryCount); } catch (error) { @@ -228,7 +166,6 @@ const SoundStudioContent: React.FC = ({ setStatus('error'); setErrorMessage(error instanceof Error ? error.message : '음악 재생성 중 오류가 발생했습니다.'); setRetryCount(0); - clearStorage(); } }; @@ -367,7 +304,6 @@ const SoundStudioContent: React.FC = ({ } setLyrics(lyricDetailResponse.lyric_result); - setShowLyrics(true); setStatus('generating_song'); setStatusMessage('노래를 생성하고 있습니다...'); @@ -395,7 +331,6 @@ const SoundStudioContent: React.FC = ({ setStatus('polling'); setStatusMessage('노래를 생성하고 있습니다...'); - saveToStorage(songResponse.task_id, songResponse.song_id, lyricDetailResponse.lyric_result, 'polling'); await resumePolling(songResponse.task_id, songResponse.song_id, lyricDetailResponse.lyric_result, 0); @@ -404,12 +339,10 @@ const SoundStudioContent: React.FC = ({ setStatus('error'); setErrorMessage(error instanceof Error ? error.message : '음악 생성 중 오류가 발생했습니다.'); setRetryCount(0); - clearStorage(); } }; const handleRegenerate = async () => { - setShowLyrics(false); setAudioUrl(null); setLyrics(''); setProgress(0); @@ -417,7 +350,6 @@ const SoundStudioContent: React.FC = ({ setDuration(0); setIsPlaying(false); setRetryCount(0); - clearStorage(); await handleGenerateMusic(); };