import React, { useState, useEffect } from 'react'; import { Layers, Sparkles, Upload, Play, RefreshCw, Film, Download, Trash2, CheckCircle2, Clock, AlertCircle, Cloud, FileSpreadsheet, Plus, } from 'lucide-react'; import { api } from '../api'; import type { AspectRatio, BrandKit, FrozenRecipe } from '@olokaflow/shared'; import { Button, Badge } from './ui/primitives'; interface Props { catalog: any; brands: BrandKit[]; recipes: FrozenRecipe[]; onOpenProjectInStudio: (projectId: string) => void; onRefreshAll: () => void; } export const BatchStudioView: React.FC = ({ catalog, brands, recipes, onOpenProjectInStudio, onRefreshAll, }) => { const [batches, setBatches] = useState([]); const [batchName, setBatchName] = useState(''); const [bulkLinesText, setBulkLinesText] = useState(''); const [defaultAspectRatio, setDefaultAspectRatio] = useState('9:16'); const [defaultVoiceId, setDefaultVoiceId] = useState('Hải Đăng'); const [defaultFramePresetId, setDefaultFramePresetId] = useState( 'editorial-clean-light' ); const [brandKitId, setBrandKitId] = useState(''); const [recipeId, setRecipeId] = useState(''); const [creationMode, setCreationMode] = useState<'auto' | 'storyboard_review'>( 'auto' ); const [autoRenderModal, setAutoRenderModal] = useState(false); const [startingBatch, setStartingBatch] = useState(false); const voicesList = catalog?.voices || []; const presetsList = catalog?.framePresets || []; async function loadBatches() { try { const res = await api.getBatches(); setBatches(res.batches || []); } catch {} } useEffect(() => { void loadBatches(); }, []); // Poll while any batch is running useEffect(() => { const hasRunning = batches.some((b) => b.status === 'running'); if (!hasRunning) return; const timer = setInterval(() => { void loadBatches(); onRefreshAll(); }, 4000); return () => clearInterval(timer); }, [batches]); function parseBulkLines(): Array<{ title?: string; prompt: string }> { return bulkLinesText .split(/\r?\n/) .map((line) => line.trim()) .filter((line) => line.length > 0 && !line.startsWith('#')) .map((line) => { // Support "Title | Prompt or URL" or CSV "Title,Prompt" if (line.includes('|')) { const [t, ...rest] = line.split('|'); return { title: t.trim(), prompt: rest.join('|').trim() }; } return { prompt: line }; }); } function handleCsvFileUpload(e: React.ChangeEvent) { const file = e.target.files?.[0]; if (!file) return; const reader = new FileReader(); reader.onload = () => { const text = String(reader.result || ''); const rows = text .split(/\r?\n/) .map((r) => r.trim()) .filter(Boolean); const converted = rows .filter((r, i) => !(i === 0 && /title|prompt|url/i.test(r))) .map((r) => { const cols = r.split(','); if (cols.length >= 2) { return `${cols[0].replace(/^"|"$/g, '').trim()} | ${cols .slice(1) .join(',') .replace(/^"|"$/g, '') .trim()}`; } return r; }); setBulkLinesText((prev) => prev ? `${prev}\n${converted.join('\n')}` : converted.join('\n') ); }; reader.readAsText(file); e.target.value = ''; } async function handleStartBatch(e: React.FormEvent) { e.preventDefault(); const items = parseBulkLines(); if (items.length === 0) return; setStartingBatch(true); try { const res = await api.createBatch({ name: batchName.trim() || undefined, items, defaultAspectRatio, defaultVoiceId, defaultFramePresetId, brandKitId: brandKitId || undefined, recipeId: recipeId || undefined, creationMode, autoRenderModal, }); setBatches(res.batches || []); setBulkLinesText(''); setBatchName(''); onRefreshAll(); } catch (err: any) { alert(`Lỗi tạo Batch: ${err.message}`); } finally { setStartingBatch(false); } } const parsedItemsCount = parseBulkLines().length; return (
{/* Header Banner */}
Batch URL-to-Video Factory • Multi-Project Automation

Sản Xuất Video Hàng Loạt Từ Danh Sách URL Sản Phẩm Hoặc CSV

Nhập nhiều link trang web sản phẩm hoặc danh sách kịch bản (mỗi dòng 1 video) — Hệ thống tự động cào ảnh, đọc giọng OlokaTTS, dựng HyperFrames 60fps và tùy chọn xuất MP4 hàng loạt qua Modal Cloud.

{/* Batch Configuration Form */}