local storage 삭제 .

main
hbyang 2026-01-22 13:31:18 +09:00
parent 00b85834fd
commit 16ef7bd97d
1 changed files with 0 additions and 68 deletions

View File

@ -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<string, string> = {
@ -55,7 +45,6 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
const [progress, setProgress] = useState(0);
const [isDragging, setIsDragging] = useState(false);
const [status, setStatus] = useState<GenerationStatus>('idle');
const [showLyrics, setShowLyrics] = useState(false);
const [lyrics, setLyrics] = useState('');
const [audioUrl, setAudioUrl] = useState<string | null>(null);
const [isPlaying, setIsPlaying] = useState(false);
@ -71,53 +60,6 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
const audioRef = useRef<HTMLAudioElement>(null);
const languageDropdownRef = useRef<HTMLDivElement>(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<SoundStudioContentProps> = ({
setStatus('complete');
setStatusMessage('');
setRetryCount(0);
clearStorage();
} catch (error) {
console.error('Polling failed:', error);
@ -183,13 +124,11 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
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<SoundStudioContentProps> = ({
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<SoundStudioContentProps> = ({
setStatus('error');
setErrorMessage(error instanceof Error ? error.message : '음악 재생성 중 오류가 발생했습니다.');
setRetryCount(0);
clearStorage();
}
};
@ -367,7 +304,6 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
}
setLyrics(lyricDetailResponse.lyric_result);
setShowLyrics(true);
setStatus('generating_song');
setStatusMessage('노래를 생성하고 있습니다...');
@ -395,7 +331,6 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
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<SoundStudioContentProps> = ({
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<SoundStudioContentProps> = ({
setDuration(0);
setIsPlaying(false);
setRetryCount(0);
clearStorage();
await handleGenerateMusic();
};