feat: Creatomate API integration — real video generation in Content Studio
- Add creatomateVideoGen.ts service with polling-based async rendering - Replace video stub (setTimeout) with actual Creatomate API calls - Add video preview (<video> tag) and MP4 download support - Build programmatic source (branded slideshow) without pre-built templates - Error handling: auth, rate limit, render failure → Korean messages Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
200497fa1e
commit
9bf47f7d93
2 files changed
+241
-9
No files matched your search
@@ -3,6 +3,7 @@ import { motion } from 'motion/react';
|
||||
import { VideoFilled, FileTextFilled } from '../icons/FilledIcons';
|
||||
import { CHANNEL_OPTIONS, MUSIC_TRACKS, type StudioState, type GenerateOutputType } from '../../types/studio';
|
||||
import { generateImage, type GenerateResult } from '../../services/geminiImageGen';
|
||||
import { generateVideo, type VideoResult } from '../../services/creatomateVideoGen';
|
||||
|
||||
interface Props {
|
||||
studioState: StudioState;
|
||||
@@ -15,6 +16,7 @@ type GenerateStatus = 'idle' | 'generating' | 'done' | 'error';
|
||||
export default function GeneratePreviewStep({ studioState, outputType, onOutputTypeChange }: Props) {
|
||||
const [status, setStatus] = useState<GenerateStatus>('idle');
|
||||
const [result, setResult] = useState<GenerateResult | null>(null);
|
||||
const [videoResult, setVideoResult] = useState<VideoResult | null>(null);
|
||||
const [errorMsg, setErrorMsg] = useState('');
|
||||
const downloadRef = useRef<HTMLAnchorElement>(null);
|
||||
|
||||
@@ -37,24 +39,38 @@ export default function GeneratePreviewStep({ studioState, outputType, onOutputT
|
||||
setStatus('error');
|
||||
}
|
||||
} else {
|
||||
// Video: placeholder (Creatomate integration needed)
|
||||
setTimeout(() => setStatus('done'), 4000);
|
||||
try {
|
||||
const res = await generateVideo(studioState);
|
||||
setVideoResult(res);
|
||||
setStatus('done');
|
||||
} catch (err) {
|
||||
setErrorMsg(err instanceof Error ? err.message : '영상 생성에 실패했습니다');
|
||||
setStatus('error');
|
||||
}
|
||||
}
|
||||
}, [studioState, outputType]);
|
||||
|
||||
const handleReset = useCallback(() => {
|
||||
setStatus('idle');
|
||||
setResult(null);
|
||||
setVideoResult(null);
|
||||
setErrorMsg('');
|
||||
}, []);
|
||||
|
||||
const handleDownload = useCallback(() => {
|
||||
if (!result?.imageDataUrl || !downloadRef.current) return;
|
||||
if (!downloadRef.current) return;
|
||||
const link = downloadRef.current;
|
||||
link.href = result.imageDataUrl;
|
||||
link.download = `INFINITH_${activeChannel?.label ?? 'content'}_${activeFormat?.key ?? 'image'}.png`;
|
||||
link.click();
|
||||
}, [result, activeChannel, activeFormat]);
|
||||
|
||||
if (result?.imageDataUrl) {
|
||||
link.href = result.imageDataUrl;
|
||||
link.download = `INFINITH_${activeChannel?.label ?? 'content'}_${activeFormat?.key ?? 'image'}.png`;
|
||||
link.click();
|
||||
} else if (videoResult?.videoUrl) {
|
||||
link.href = videoResult.videoUrl;
|
||||
link.download = `INFINITH_${activeChannel?.label ?? 'content'}_${activeFormat?.key ?? 'video'}.mp4`;
|
||||
link.click();
|
||||
}
|
||||
}, [result, videoResult, activeChannel, activeFormat]);
|
||||
|
||||
const aspectClass =
|
||||
activeFormat?.aspectRatio === '9:16' ? 'w-[240px] h-[426px]' :
|
||||
@@ -126,7 +142,7 @@ export default function GeneratePreviewStep({ studioState, outputType, onOutputT
|
||||
|
||||
{status === 'done' && (
|
||||
<div className="mt-6 flex gap-3">
|
||||
{result?.imageDataUrl && (
|
||||
{(result?.imageDataUrl || videoResult?.videoUrl) && (
|
||||
<button
|
||||
onClick={handleDownload}
|
||||
className="flex-1 py-3 rounded-full bg-gradient-to-r from-[#4F1DA1] to-[#021341] text-white text-sm font-medium shadow-md hover:shadow-lg transition-all"
|
||||
@@ -197,7 +213,21 @@ export default function GeneratePreviewStep({ studioState, outputType, onOutputT
|
||||
/>
|
||||
)}
|
||||
|
||||
{status === 'done' && !result?.imageDataUrl && (
|
||||
{status === 'done' && videoResult?.videoUrl && (
|
||||
<motion.video
|
||||
src={videoResult.videoUrl}
|
||||
controls
|
||||
autoPlay
|
||||
loop
|
||||
muted
|
||||
initial={{ opacity: 0, scale: 0.95 }}
|
||||
animate={{ opacity: 1, scale: 1 }}
|
||||
transition={{ duration: 0.5 }}
|
||||
className="absolute inset-0 w-full h-full object-cover"
|
||||
/>
|
||||
)}
|
||||
|
||||
{status === 'done' && !result?.imageDataUrl && !videoResult?.videoUrl && (
|
||||
<motion.div
|
||||
initial={{ opacity: 0, scale: 0.95 }}
|
||||
animate={{ opacity: 1, scale: 1 }}
|
||||
|
||||
Reference in new issue
Block a user