브랜드 분석, 콘텐츠 완료 페이지 수정 .

This commit is contained in:
HyeongBaeYang committed 2026-02-13 17:02:01 +09:00
1 parent b89cf027af
commit e448d8189d
12 files changed
+1456 -689

No files matched your search

+225 -378
View File
@@ -1,8 +1,8 @@
import React, { useState, useEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { generateVideo, waitForVideoComplete, getYouTubeConnectUrl, getSocialAccounts, disconnectSocialAccount, TokenExpiredError, handleSocialReconnect } from '../../utils/api';
import { SocialAccount } from '../../types/api';
import { generateVideo, waitForVideoComplete } from '../../utils/api';
import SocialPostingModal from '../../components/SocialPostingModal';
interface CompletionContentProps {
onBack: () => void;
@@ -12,10 +12,9 @@ interface CompletionContentProps {
}
type VideoStatus = 'idle' | 'generating' | 'polling' | 'complete' | 'error';
const VIDEO_STORAGE_KEY = 'castad_video_generation';
const VIDEO_COMPLETE_KEY = 'castad_video_complete'; // 완료된 영상 정보 (만료 없음)
const VIDEO_STORAGE_EXPIRY = 30 * 60 * 1000; // 30분
const VIDEO_COMPLETE_KEY = 'castad_video_complete';
const VIDEO_STORAGE_EXPIRY = 30 * 60 * 1000;
interface SavedVideoState {
videoTaskId: string;
@@ -32,23 +31,31 @@ const CompletionContent: React.FC<CompletionContentProps> = ({
onVideoProgressChange
}) => {
const { t } = useTranslation();
const [selectedSocials, setSelectedSocials] = useState<string[]>([]);
const [videoStatus, setVideoStatus] = useState<VideoStatus>('idle');
const [videoUrl, setVideoUrl] = useState<string | null>(null);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [statusMessage, setStatusMessage] = useState('');
const [renderProgress, setRenderProgress] = useState(0); // 영상 렌더링 진행률 (0-100)
const [renderProgress, setRenderProgress] = useState(0);
const [isPlaying, setIsPlaying] = useState(false);
const [progress, setProgress] = useState(0);
const [showControls, setShowControls] = useState(true);
const videoRef = useRef<HTMLVideoElement>(null);
const hasStartedGeneration = useRef(false);
const hideControlsTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
// YouTube 연결 상태
const [youtubeAccount, setYoutubeAccount] = useState<SocialAccount | null>(null);
const [isYoutubeConnecting, setIsYoutubeConnecting] = useState(false);
const [youtubeError, setYoutubeError] = useState<string | null>(null);
// 소셜 미디어 포스팅 모달
const [showSocialModal, setShowSocialModal] = useState(false);
// 저장된 완료 데이터
const [songCompletionData, setSongCompletionData] = useState<{
businessName: string;
genre: string;
lyrics: string;
} | null>(null);
// 비디오 비율
const [videoRatio, setVideoRatio] = useState<'vertical' | 'horizontal'>('vertical');
// Notify parent of video status changes
useEffect(() => {
if (onVideoStatusChange) {
const mappedStatus = videoStatus === 'polling' ? 'generating' : videoStatus;
@@ -56,7 +63,6 @@ const CompletionContent: React.FC<CompletionContentProps> = ({
}
}, [videoStatus, onVideoStatusChange]);
// Notify parent of progress changes
useEffect(() => {
if (onVideoProgressChange) {
onVideoProgressChange(renderProgress);
@@ -73,7 +79,6 @@ const CompletionContent: React.FC<CompletionContentProps> = ({
};
localStorage.setItem(VIDEO_STORAGE_KEY, JSON.stringify(data));
// 완료된 경우 별도의 만료 없는 키에도 저장
if (status === 'complete' && url) {
const completeData = {
songTaskId: currentSongTaskId,
@@ -81,16 +86,13 @@ const CompletionContent: React.FC<CompletionContentProps> = ({
completedAt: Date.now(),
};
localStorage.setItem(VIDEO_COMPLETE_KEY, JSON.stringify(completeData));
console.log('[Video] Saved complete state:', completeData);
}
};
const clearStorage = () => {
localStorage.removeItem(VIDEO_STORAGE_KEY);
// 주의: VIDEO_COMPLETE_KEY는 여기서 삭제하지 않음 (명시적으로만 삭제)
};
// 완료된 영상 정보 로드 (만료 없음)
const loadCompleteVideo = (): { songTaskId: string; videoUrl: string } | null => {
try {
const saved = localStorage.getItem(VIDEO_COMPLETE_KEY);
@@ -129,7 +131,6 @@ const CompletionContent: React.FC<CompletionContentProps> = ({
setErrorMessage(null);
try {
// Get video ratio from localStorage (default to 'vertical' if not set)
const savedRatio = localStorage.getItem('castad_video_ratio');
const orientation = (savedRatio === 'horizontal' || savedRatio === 'vertical') ? savedRatio : 'vertical';
@@ -141,7 +142,6 @@ const CompletionContent: React.FC<CompletionContentProps> = ({
setVideoStatus('polling');
setStatusMessage(t('completion.generatingVideo'));
// video/status API는 creatomate_render_id를 사용
saveToStorage(videoResponse.creatomate_render_id, songTaskId, 'polling', null);
await pollVideoStatus(videoResponse.creatomate_render_id, songTaskId);
@@ -155,7 +155,6 @@ const CompletionContent: React.FC<CompletionContentProps> = ({
}
};
// 상태별 한글 메시지 및 진행률 매핑
const getStatusMessage = (status: string): string => {
switch (status) {
case 'planned':
@@ -173,7 +172,6 @@ const CompletionContent: React.FC<CompletionContentProps> = ({
}
};
// 상태별 진행률 계산
const getProgressForStatus = (status: string): number => {
switch (status) {
case 'planned':
@@ -193,7 +191,6 @@ const CompletionContent: React.FC<CompletionContentProps> = ({
const pollVideoStatus = async (videoTaskId: string, currentSongTaskId: string) => {
try {
// 영상 생성 상태 폴링 (3분 타임아웃, 3초 간격)
const statusResponse = await waitForVideoComplete(
videoTaskId,
(status: string) => {
@@ -202,7 +199,6 @@ const CompletionContent: React.FC<CompletionContentProps> = ({
}
);
// render_data.url에서 영상 URL 가져오기
const videoUrlFromResponse = statusResponse.render_data?.url;
if (videoUrlFromResponse) {
@@ -230,178 +226,65 @@ const CompletionContent: React.FC<CompletionContentProps> = ({
}
};
// 컴포넌트 마운트 시 저장된 상태 확인 또는 영상 생성 시작
useEffect(() => {
if (!songTaskId) return;
// 1. 먼저 완료된 영상 정보 확인 (만료 없음)
const completeVideo = loadCompleteVideo();
if (completeVideo && completeVideo.songTaskId === songTaskId && completeVideo.videoUrl) {
console.log('[Video] Restored from complete storage:', completeVideo);
setVideoUrl(completeVideo.videoUrl);
setVideoStatus('complete');
hasStartedGeneration.current = true;
return; // 완료된 영상이 있으면 더 이상 진행하지 않음
return;
}
// 2. 일반 저장소에서 상태 확인 (30분 만료)
const savedState = loadFromStorage();
// 저장된 상태가 있고, 같은 songTaskId인 경우
if (savedState && savedState.songTaskId === songTaskId) {
if (savedState.status === 'complete' && savedState.videoUrl) {
// 이미 완료된 경우
setVideoUrl(savedState.videoUrl);
setVideoStatus('complete');
hasStartedGeneration.current = true;
} else if (savedState.status === 'polling') {
// 폴링 중이었던 경우 다시 폴링
setVideoStatus('polling');
setStatusMessage(t('completion.processingAfterRefresh'));
hasStartedGeneration.current = true;
pollVideoStatus(savedState.videoTaskId, savedState.songTaskId);
}
} else if (!hasStartedGeneration.current) {
// 새로운 영상 생성 시작
startVideoGeneration();
}
}, [songTaskId]);
// localStorage에서 방금 연결된 계정 정보 확인
const SOCIAL_CONNECTED_KEY = 'castad_social_connected';
const checkLocalStorageForConnectedAccount = () => {
try {
const saved = localStorage.getItem(SOCIAL_CONNECTED_KEY);
if (saved) {
const connectedAccount = JSON.parse(saved);
console.log('[YouTube] Found connected account in localStorage:', connectedAccount);
if (connectedAccount.platform === 'youtube') {
// localStorage에서 계정 정보로 즉시 UI 업데이트
setYoutubeAccount({
id: parseInt(connectedAccount.account_id, 10),
platform: 'youtube',
platform_user_id: connectedAccount.account_id,
platform_username: connectedAccount.channel_name,
display_name: connectedAccount.channel_name,
is_active: true,
connected_at: connectedAccount.connected_at,
profile_image: connectedAccount.profile_image,
});
// localStorage에서 제거 (일회성 사용)
localStorage.removeItem(SOCIAL_CONNECTED_KEY);
return true;
}
}
} catch (error) {
console.error('[YouTube] Failed to parse localStorage:', error);
}
return false;
};
// YouTube 연결 상태 확인 (API 호출 - /social/oauth/accounts)
const checkYoutubeConnection = async () => {
try {
console.log('[YouTube] Checking connection status from API...');
const response = await getSocialAccounts();
console.log('[YouTube] Accounts response:', response);
// accounts 배열에서 youtube 플랫폼 찾기
const youtubeAcc = response.accounts?.find(acc => acc.platform === 'youtube' && acc.is_active);
if (youtubeAcc) {
setYoutubeAccount(youtubeAcc);
console.log('[YouTube] Account connected:', youtubeAcc.display_name);
} else {
setYoutubeAccount(null);
console.log('[YouTube] No YouTube account connected');
}
} catch (error) {
if (error instanceof TokenExpiredError) {
alert(t('completion.youtubeExpiredAlert'));
handleSocialReconnect(error.reconnectUrl);
return;
}
console.error('[YouTube] Failed to check connection:', error);
// API 에러 시에도 localStorage에서 확인한 값 유지
}
};
// 완료 데이터 로드
useEffect(() => {
// 먼저 localStorage에서 방금 연결된 계정 확인
const foundInLocalStorage = checkLocalStorageForConnectedAccount();
try {
const saved = localStorage.getItem('castad_song_completion');
if (saved) {
const data = JSON.parse(saved);
setSongCompletionData(data);
}
} catch (error) {
console.error('Failed to load song completion data:', error);
}
// localStorage에 없으면 API로 확인
if (!foundInLocalStorage) {
checkYoutubeConnection();
} else {
// localStorage에서 찾았어도 API로 최신 정보 갱신 (백그라운드)
checkYoutubeConnection();
// 비디오 비율 로드
const savedRatio = localStorage.getItem('castad_video_ratio');
if (savedRatio === 'horizontal' || savedRatio === 'vertical') {
setVideoRatio(savedRatio);
}
}, []);
// YouTube 연결 핸들러
const handleYoutubeConnect = async () => {
if (youtubeAccount) {
// 이미 연결된 경우 선택/해제만 토글
toggleSocial('Youtube');
return;
}
setIsYoutubeConnecting(true);
setYoutubeError(null);
try {
const response = await getYouTubeConnectUrl();
// OAuth URL로 리다이렉트
window.location.href = response.auth_url;
} catch (error) {
if (error instanceof TokenExpiredError) {
alert(t('completion.youtubeExpiredAlert'));
handleSocialReconnect(error.reconnectUrl);
return;
}
console.error('YouTube connect failed:', error);
setYoutubeError(t('completion.youtubeConnectFailed'));
setIsYoutubeConnecting(false);
}
};
// YouTube 연결 해제 핸들러
const handleYoutubeDisconnect = async () => {
if (!youtubeAccount) return;
try {
await disconnectSocialAccount(youtubeAccount.id);
setYoutubeAccount(null);
setSelectedSocials(prev => prev.filter(s => s !== 'Youtube'));
} catch (error) {
if (error instanceof TokenExpiredError) {
alert(t('completion.youtubeExpiredAlert'));
handleSocialReconnect(error.reconnectUrl);
return;
}
console.error('YouTube disconnect failed:', error);
setYoutubeError(t('completion.disconnectFailed'));
}
};
const toggleSocial = (id: string) => {
setSelectedSocials(prev =>
prev.includes(id)
? prev.filter(s => s !== id)
: [...prev, id]
);
};
const togglePlayPause = () => {
if (!videoRef.current || !videoUrl) return;
if (isPlaying) {
videoRef.current.pause();
setShowControls(true);
if (hideControlsTimer.current) clearTimeout(hideControlsTimer.current);
} else {
videoRef.current.play();
hideControlsTimer.current = setTimeout(() => {
setShowControls(false);
}, 3000);
}
setIsPlaying(!isPlaying);
};
@@ -415,6 +298,36 @@ const CompletionContent: React.FC<CompletionContentProps> = ({
const handleVideoEnded = () => {
setIsPlaying(false);
setProgress(0);
setShowControls(true);
};
const resetHideControlsTimer = () => {
if (hideControlsTimer.current) {
clearTimeout(hideControlsTimer.current);
}
setShowControls(true);
if (isPlaying) {
hideControlsTimer.current = setTimeout(() => {
setShowControls(false);
}, 3000);
}
};
const handleVideoMouseEnter = () => {
resetHideControlsTimer();
};
const handleVideoMouseMove = () => {
resetHideControlsTimer();
};
const handleVideoMouseLeave = () => {
if (isPlaying) {
if (hideControlsTimer.current) clearTimeout(hideControlsTimer.current);
hideControlsTimer.current = setTimeout(() => {
setShowControls(false);
}, 1000);
}
};
const handleDownload = () => {
@@ -429,27 +342,12 @@ const CompletionContent: React.FC<CompletionContentProps> = ({
}
};
// 소셜 채널에 배포
const handleDeploy = () => {
if (selectedSocials.length === 0) {
alert(t('completion.selectSocialChannel'));
return;
}
const handleOpenSocialConnect = () => {
setShowSocialModal(true);
};
if (!videoUrl) {
alert(t('completion.videoNotReady'));
return;
}
// 선택된 채널 중 YouTube가 있고 연결된 경우
if (selectedSocials.includes('Youtube') && youtubeAccount) {
// TODO: YouTube 업로드 API 호출
alert(t('completion.youtubeUploadMessage', { channelName: youtubeAccount.display_name }));
return;
}
// 다른 플랫폼 선택 시
alert(t('completion.deployComingSoon'));
const handleCloseSocialConnect = () => {
setShowSocialModal(false);
};
const handleRetry = () => {
@@ -461,224 +359,173 @@ const CompletionContent: React.FC<CompletionContentProps> = ({
startVideoGeneration();
};
const socials = [
{
id: 'Youtube',
logo: '/assets/images/social-youtube.png',
connected: !!youtubeAccount,
channelName: youtubeAccount?.display_name || null,
thumbnailUrl: youtubeAccount?.profile_image || null,
isConnecting: isYoutubeConnecting,
},
{ id: 'Instagram', logo: '/assets/images/social-instagram.png', connected: false, channelName: null, thumbnailUrl: null, isConnecting: false },
{ id: 'Facebook', logo: '/assets/images/social-facebook.png', connected: false, channelName: null, thumbnailUrl: null, isConnecting: false },
];
const isLoading = videoStatus === 'generating' || videoStatus === 'polling';
// 비디오 해상도 계산
const getVideoResolution = () => {
const savedRatio = localStorage.getItem('castad_video_ratio');
return savedRatio === 'horizontal' ? '1234×720' : '720×1234';
};
// 파일명 생성
const getFileName = () => {
const businessName = songCompletionData?.businessName || '콘텐츠';
return `${businessName}.mp4`;
};
return (
<main className="page-container">
{/* Header with Back Button */}
<div className="asset-header">
<button onClick={onBack} className="btn-back-new">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M15 18l-6-6 6-6" />
</svg>
<span>{t('completion.back')}</span>
</button>
</div>
<main className="comp2-page">
<div className="comp2-header">
<button onClick={onBack} className="comp2-back-btn">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M15 18l-6-6 6-6" />
</svg>
<span>{t('completion.back')}</span>
</button>
</div>
{/* Title */}
<h1 className="completion-title">
{isLoading ? t('completion.titleGenerating') : videoStatus === 'error' ? t('completion.titleError') : t('completion.titleComplete')}
</h1>
<div className="comp2-title-row">
<h1 className="comp2-page-title">{t('completion.contentComplete', { defaultValue: '콘텐츠 제작 완료' })}</h1>
<p className="comp2-page-subtitle">{t('completion.contentCompleteDesc', { defaultValue: 'AI 분석 및 편집을 통해 최적화된 콘텐츠가 완성되었습니다' })}</p>
</div>
{/* Main Content Container */}
<div className="completion-container">
{/* Left: Video Preview */}
<div className="completion-column completion-column-left video-preview-card">
<h3 className="asset-section-title">{t('completion.imageAndVideo')}</h3>
<div className="completion-video-wrapper">
<div className="video-container">
{isLoading ? (
/* Loading State */
<div className="video-loading">
<div className="loading-spinner">
<div className="loading-ring"></div>
<div className="loading-dot">
<div className="loading-dot-inner"></div>
<div className="comp2-container">
<div className="comp2-grid">
{/* 왼쪽: 영상 */}
<div className="comp2-video-section">
<div className="comp2-video-wrapper" onMouseEnter={handleVideoMouseEnter} onMouseMove={handleVideoMouseMove} onMouseLeave={handleVideoMouseLeave}>
{isLoading ? (
<div className="comp2-video-loading">
<div className="loading-spinner">
<div className="loading-ring"></div>
<div className="loading-dot">
<div className="loading-dot-inner"></div>
</div>
</div>
<p className="comp2-loading-text">{statusMessage}</p>
</div>
<p className="text-gray-400 mt-4">{statusMessage}</p>
</div>
) : videoStatus === 'error' ? (
/* Error State */
<div className="video-error">
<svg className="w-16 h-16 text-red-500 mb-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<circle cx="12" cy="12" r="10" />
<path d="M12 8v4M12 16h.01" />
</svg>
<p className="text-gray-400 mb-4">{errorMessage}</p>
<button onClick={handleRetry} className="btn-secondary">
{t('completion.retry')}
</button>
</div>
) : videoUrl ? (
<>
{/* Video Player */}
<video
ref={videoRef}
src={videoUrl}
className="video-player"
onTimeUpdate={handleTimeUpdate}
onEnded={handleVideoEnded}
onClick={togglePlayPause}
/>
</>
) : (
<div className="video-pattern"></div>
)}
{/* Video Player Controls - only show when video is ready */}
{videoStatus === 'complete' && videoUrl && (
<div className="video-controls">
<div className="video-controls-inner">
<button className="video-play-btn" onClick={togglePlayPause}>
{isPlaying ? (
<svg className="w-7 h-7" viewBox="0 0 24 24" fill="currentColor"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/></svg>
) : (
<svg className="w-7 h-7" viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>
)}
) : videoStatus === 'error' ? (
<div className="comp2-video-error">
<svg className="comp2-error-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<circle cx="12" cy="12" r="10" />
<path d="M12 8v4M12 16h.01" />
</svg>
<p className="comp2-error-text">{errorMessage}</p>
<button onClick={handleRetry} className="comp2-retry-btn">
{t('completion.retry')}
</button>
<div className="video-progress">
<div className="video-progress-fill" style={{ width: `${progress}%` }}></div>
</div>
) : videoUrl ? (
<>
<video
ref={videoRef}
src={videoUrl}
className="comp2-video-player"
onTimeUpdate={handleTimeUpdate}
onEnded={handleVideoEnded}
onClick={togglePlayPause}
/>
<div className={`comp2-video-controls ${showControls ? 'visible' : 'hidden'}`}>
<div className="comp2-progress-bar">
<div className="comp2-progress-fill" style={{ width: `${progress}%` }}></div>
</div>
<div className="comp2-controls-row">
<button className="comp2-play-btn" onClick={togglePlayPause}>
{isPlaying ? (
<svg width="32" height="32" viewBox="0 0 24 24" fill="currentColor">
<path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/>
</svg>
) : (
<svg width="32" height="32" viewBox="0 0 24 24" fill="currentColor">
<path d="M8 5v14l11-7z"/>
</svg>
)}
</button>
<div className="comp2-volume-control">
<svg width="32" height="32" viewBox="0 0 24 24" fill="currentColor">
<path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02z"/>
</svg>
<div className="comp2-volume-bar">
<div className="comp2-volume-fill"></div>
</div>
</div>
<div className="comp2-time-display">
<span className="comp2-time-current">00:04</span>
<span className="comp2-time-divider">/</span>
<span className="comp2-time-total">00:34</span>
</div>
</div>
</div>
</div>
</div>
)}
</div>
</div>
{/* AI Optimization Tags - only show when complete */}
{videoStatus === 'complete' && (
<div className="ai-optimization-section">
<h3 className="ai-optimization-title">{t('completion.aiOptimization')}</h3>
<div className="ai-optimization-tags">
{[
{ key: 'colorCorrection', label: t('completion.aiTagColorCorrection') },
{ key: 'dynamicSubtitle', label: t('completion.aiTagDynamicSubtitle') },
{ key: 'beatSync', label: t('completion.aiTagBeatSync') },
{ key: 'seoMeta', label: t('completion.aiTagSEOMeta') },
].map(tag => (
<div key={tag.key} className="ai-tag">
<div className="ai-tag-dot"></div>
<span className="ai-tag-text">{tag.label}</span>
</div>
))}
</>
) : (
<div className="comp2-video-placeholder"></div>
)}
</div>
</div>
)}
</div>
{/* Right: Sharing */}
<div className="completion-column completion-column-right sharing-card">
<div className="sharing-content">
<h3 className="asset-section-title">{t('completion.sharing')}</h3>
<div className="social-list-new">
{socials.map(social => {
const isSelected = selectedSocials.includes(social.id);
const isYoutube = social.id === 'Youtube';
return (
<div
key={social.id}
onClick={() => {
if (videoStatus !== 'complete') return;
if (isYoutube) {
handleYoutubeConnect();
} else {
// Instagram, Facebook은 아직 미구현
}
}}
className={`completion-social-card ${videoStatus !== 'complete' ? 'disabled' : ''} ${social.connected ? 'connected' : ''} ${isSelected ? 'selected' : ''}`}
>
<div className="completion-social-info">
{/* 연결된 경우 채널 썸네일 표시, 아니면 플랫폼 로고 */}
{social.connected && social.thumbnailUrl ? (
<img src={social.thumbnailUrl} alt={social.channelName || social.id} className="completion-social-thumbnail" />
) : (
<img src={social.logo} alt={social.id} className="completion-social-logo" />
)}
<div className="completion-social-text">
{social.connected && social.channelName ? (
<>
<span className="completion-social-channel-name">{social.channelName}</span>
<span className="completion-social-platform">{social.id}</span>
</>
) : (
<span className="completion-social-name">{social.id}</span>
)}
</div>
</div>
{social.isConnecting ? (
<span className="completion-social-status connecting">{t('completion.connecting')}</span>
) : social.connected ? (
<div className="completion-social-actions">
<span className="completion-social-status connected">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5">
<polyline points="20 6 9 17 4 12" />
</svg>
{t('completion.authenticated')}
</span>
{isYoutube && (
<button
onClick={(e) => {
e.stopPropagation();
handleYoutubeDisconnect();
}}
className="completion-social-disconnect"
>
{t('completion.disconnect')}
</button>
)}
</div>
) : (
<span className="completion-social-status not-connected">
{isYoutube ? t('completion.connectAccount') : t('completion.comingSoon')}
</span>
)}
{/* 오른쪽: 콘텐츠 정보 */}
<div className="comp2-info-section">
<div className="comp2-info-header">
<span className="comp2-info-label">{t('completion.contentInfo', { defaultValue: '콘텐츠 정보' })}</span>
</div>
<div className="comp2-info-content">
<div className="comp2-file-info">
<h3 className="comp2-filename">{getFileName()}</h3>
<p className="comp2-filesize">19.6MB</p>
</div>
<div className="comp2-meta-grid">
<div className="comp2-meta-item">
<span className="comp2-meta-label">{t('completion.genre', { defaultValue: '장르' })} : {songCompletionData?.genre || 'K-POP'}</span>
</div>
);
})}
{youtubeError && (
<p className="text-red-400 text-sm mt-2">{youtubeError}</p>
)}
<div className="comp2-meta-divider"></div>
<div className="comp2-meta-item">
<span className="comp2-meta-label">{t('completion.resolution', { defaultValue: '규격' })} : {getVideoResolution()}</span>
</div>
<div className="comp2-meta-divider"></div>
<div className="comp2-lyrics-section">
<span className="comp2-meta-label">{t('completion.lyrics', { defaultValue: '가사' })}</span>
<p className="comp2-lyrics-text">
{songCompletionData?.lyrics || t('completion.sampleLyrics', { defaultValue: '가사를 불러오는 중...' })}
</p>
</div>
</div>
</div>
{/* 하단 버튼 */}
<div className="comp2-buttons">
<button
onClick={handleDownload}
disabled={videoStatus !== 'complete' || !videoUrl}
className="comp2-btn comp2-btn-secondary"
>
{t('completion.download', { defaultValue: '다운로드' })}
</button>
<button
onClick={handleOpenSocialConnect}
disabled={videoStatus !== 'complete'}
className="comp2-btn comp2-btn-primary"
>
{t('completion.uploadToSocial', { defaultValue: '소셜 채널 업로드' })}
</button>
</div>
</div>
</div>
<div className="sharing-actions">
<button
onClick={handleDeploy}
disabled={selectedSocials.length === 0 || videoStatus !== 'complete'}
className="btn-completion-deploy"
>
{t('completion.deployToSocial')}
</button>
<button
onClick={handleDownload}
disabled={videoStatus !== 'complete' || !videoUrl}
className="btn-completion-download"
>
{t('completion.downloadMp4')}
</button>
</div>
</div>
</div>
</main>
);
{/* 소셜 미디어 포스팅 모달 (기존 SocialPostingModal 컴포넌트 사용) */}
<SocialPostingModal
isOpen={showSocialModal}
onClose={handleCloseSocialConnect}
video={videoUrl ? {
video_id: 0,
store_name: songCompletionData?.businessName || '',
region: '',
task_id: songTaskId || '',
result_movie_url: videoUrl,
created_at: new Date().toISOString(),
} : null}
/>
</main>
);
};
export default CompletionContent;
+11 -2
View File
@@ -144,6 +144,7 @@ const GenerationFlow: React.FC<GenerationFlowProps> = ({
// analysisData 변경 시 imageList 업데이트
useEffect(() => {
console.log('[GenerationFlow] analysisData updated, m_id:', analysisData?.m_id);
if (analysisData?.image_list && analysisData.image_list.length > 0) {
setImageList(analysisData.image_list.map(url => ({ type: 'url', url })));
}
@@ -195,6 +196,7 @@ const GenerationFlow: React.FC<GenerationFlowProps> = ({
try {
const data = await autocomplete(request);
console.log('[Autocomplete] Response m_id:', data.m_id);
// 기본값 보장
if (data.marketing_analysis) {
@@ -219,9 +221,14 @@ const GenerationFlow: React.FC<GenerationFlowProps> = ({
}
};
// 테스트용 랜덤 m_id 생성 (99 ~ 300)
const generateRandomMId = (): number => {
return Math.floor(Math.random() * (300 - 99 + 1)) + 99;
};
// 테스트 데이터로 브랜드 분석 페이지 이동
const handleTestData = (data: CrawlingResponse) => {
const tagged = { ...data, _isTestData: true };
const tagged = { ...data, m_id: generateRandomMId(), _isTestData: true };
setAnalysisData(tagged);
localStorage.setItem(ANALYSIS_DATA_KEY, JSON.stringify(tagged));
goToWizardStep(0); // 브랜드 분석 결과로
@@ -238,7 +245,8 @@ const GenerationFlow: React.FC<GenerationFlowProps> = ({
fetch(jsonFile)
.then(res => res.json())
.then((data: CrawlingResponse) => {
const tagged = { ...data, _isTestData: true };
// 언어 변경 시에는 기존 m_id 유지
const tagged = { ...data, m_id: parsed.m_id || generateRandomMId(), _isTestData: true };
setAnalysisData(tagged);
localStorage.setItem(ANALYSIS_DATA_KEY, JSON.stringify(tagged));
})
@@ -255,6 +263,7 @@ const GenerationFlow: React.FC<GenerationFlowProps> = ({
try {
const data = await crawlUrl(url);
console.log('[Crawl] Response m_id:', data.m_id);
// 기본값 보장
if (data.marketing_analysis) {
+25 -10
View File
@@ -64,6 +64,17 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
const audioRef = useRef<HTMLAudioElement>(null);
const languageDropdownRef = useRef<HTMLDivElement>(null);
// 완료 데이터를 localStorage에 저장
const saveSongCompletionData = () => {
const completionData = {
businessName: businessInfo?.customer_name || '알 수 없음',
genre: selectedGenre === '자동 선택' ? 'K-POP' : selectedGenre,
lyrics: lyrics,
timestamp: Date.now(),
};
localStorage.setItem('castad_song_completion', JSON.stringify(completionData));
};
// Close language dropdown when clicking outside
useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
@@ -84,6 +95,8 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
// Auto-navigate to next page when video generation is complete
useEffect(() => {
if (videoGenerationStatus === 'complete' && songTaskId) {
// Save completion data before navigating
saveSongCompletionData();
// Wait a brief moment to show 100% completion before navigating
const timer = setTimeout(() => {
onNext(songTaskId);
@@ -277,6 +290,7 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
const language = LANGUAGE_MAP[selectedLang] || 'Korean';
// 1. 가사 생성 요청
console.log('[SoundStudio] Sending m_id:', mId);
const lyricResponse = await generateLyric({
customer_name: businessInfo.customer_name,
detail_region_info: businessInfo.detail_region_info,
@@ -404,20 +418,16 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
{[
{ key: '보컬', label: t('soundStudio.soundTypeVocal') },
{ key: '배경음악', label: t('soundStudio.soundTypeBGM') },
{ key: '성우 내레이션', label: t('soundStudio.soundTypeNarration') },
].map(({ key, label }) => {
const isDisabled = key === '성우 내레이션' || isGenerating;
return (
].map(({ key, label }) => (
<button
key={key}
onClick={() => !isDisabled && setSelectedType(key)}
disabled={isDisabled}
className={`sound-type-btn ${selectedType === key ? 'active' : ''} ${key === '성우 내레이션' ? 'permanently-disabled' : ''}`}
onClick={() => !isGenerating && setSelectedType(key)}
disabled={isGenerating}
className={`sound-type-btn ${selectedType === key ? 'active' : ''}`}
>
{label}
</button>
);
})}
))}
</div>
</div>
@@ -608,7 +618,12 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
{/* Bottom Button */}
<div className="bottom-button-container">
<button
onClick={() => songTaskId && onNext(songTaskId)}
onClick={() => {
if (songTaskId) {
saveSongCompletionData();
onNext(songTaskId);
}
}}
disabled={status !== 'complete' || !songTaskId || videoGenerationStatus === 'generating'}
className={`btn-video-generate ${
videoGenerationStatus === 'generating'