Spaces:
Sleeping
Sleeping
Update index.html
Browse files7 unmodified lines89101112131415161718192021222324252627282930313233343536373839404142431 unmodified line454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322337 unmodified lines<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script><script src="https://unpkg.com/@babel/standalone/babel.min.js"></script><script src="https://cdn.tailwindcss.com"></script><!-- Lucide Icons の読み込み --><script src="https://unpkg.com/lucide@latest"></script></head><body class="bg-slate-50"><div id="root"></div><script type="text/babel">const { useState, useEffect, useRef } = React;// アイコンコンポーネントconst Icon = ({ name, className = "" }) => {useEffect(() => {if (window.lucide) {window.lucide.createIcons();}}, [name]);return <i data-lucide={name} className={className}></i>;};const TOOLS = [{ id: 'heic-jpg', title: 'HEIC → JPG', icon: 'image', color: 'bg-blue-500', description: 'iPhoneの写真を一般的な形式に変換' },{ id: 'm4a-mp3', title: 'M4A → MP3', icon: 'music', color: 'bg-purple-500', description: '録音データをMP3に圧縮変換' },{ id: 'mp4-mp3', title: 'MP4 → MP3', icon: 'video', color: 'bg-red-500', description: '動画から音声のみを抽出' },{ id: 'jpeg-pdf', title: 'JPEG → PDF', icon: 'file-text', color: 'bg-green-500', description: '複数の画像を1つのPDFに結合' },{ id: 'pdf-png', title: 'PDF → PNG', icon: 'image', color: 'bg-orange-500', description: 'PDFを画像として保存' },{ id: 'youtube', title: 'YouTube保存', icon: 'youtube', color: 'bg-rose-600', description: 'URLから動画をダウンロード' },];function App() {const [currentPage, setCurrentPage] = useState('main');const [selectedTool, setSelectedTool] = useState(null);const [taskState, setTaskState] = useState({ id: null, status: 'idle', progress: 0, logs: [] });const [files, setFiles] = useState([]);const [url, setUrl] = useState('');1 unmodified lineconst [downloadUrl, setDownloadUrl] = useState(null);const pollInterval = useRef(null);const resetTask = () => {if (pollInterval.current) clearInterval(pollInterval.current);setTaskState({ id: null, status: 'idle', progress: 0, logs: [] });setFiles([]);setUrl('');setError('');setDownloadUrl(null);};const backToMain = () => {resetTask();setCurrentPage('main');setSelectedTool(null);};const addLog = (msg) => {setTaskState(prev => ({ ...prev, logs: [...prev.logs.slice(-4), msg] }));};const pollTaskStatus = async (taskId) => {try {const response = await fetch(`/api/status/${taskId}`);const data = await response.json();if (data.status === 'completed') {clearInterval(pollInterval.current);setTaskState(prev => ({ ...prev, status: 'completed', progress: 100 }));setDownloadUrl(`/api/download/${taskId}`);addLog("完了しました。");} else if (data.status === 'failed') {clearInterval(pollInterval.current);setError(data.error || "エラーが発生しました");setTaskState(prev => ({ ...prev, status: 'failed' }));} else {setTaskState(prev => ({ ...prev, progress: data.progress || prev.progress }));if (data.last_log) addLog(data.last_log);}} catch (err) { console.error(err); }};const startProcessing = async () => {setTaskState({ id: null, status: 'uploading', progress: 10, logs: ['アップロード中...'] });setError('');try {const formData = new FormData();formData.append('tool_id', selectedTool.id);if (selectedTool.id === 'youtube') {if(!url) throw new Error("URLを入力してください");formData.append('url', url);} else {if(files.length === 0) throw new Error("ファイルを選択してください");files.forEach(f => formData.append('files', f));}const response = await fetch('/api/convert', { method: 'POST', body: formData });const data = await response.json();const task_id = data.task_id;setTaskState(prev => ({ ...prev, id: task_id, status: 'processing', progress: 20 }));pollInterval.current = setInterval(() => pollTaskStatus(task_id), 2000);} catch (err) {setError(err.message);setTaskState(prev => ({ ...prev, status: 'idle' }));}};return (<div className="min-h-screen p-4 md:p-8"><div className="max-w-4xl mx-auto">{currentPage === 'main' ? (<div className="animate-in fade-in duration-500"><h1 className="text-4xl font-black mb-12 text-center text-slate-900">MediaMaster <span className="text-indigo-600">Async</span></h1><div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">{TOOLS.map(t => (<divkey={t.id}onClick={() => { setSelectedTool(t); setCurrentPage('tool'); }}className="bg-white p-6 rounded-3xl shadow-sm hover:shadow-xl cursor-pointer transition-all border border-slate-100 group"><div className={`${t.color} w-12 h-12 rounded-2xl flex items-center justify-center text-white mb-4 group-hover:scale-110 transition-transform`}><Icon name={t.icon} /></div><h3 className="font-bold text-lg mb-1">{t.title}</h3><p className="text-xs text-slate-400 leading-relaxed">{t.description}</p></div>))}</div></div>) : (<div className="max-w-xl mx-auto animate-in slide-in-from-bottom-4 duration-500">{/* メインに戻るボタン */}<buttononClick={backToMain}className="flex items-center gap-2 text-slate-400 hover:text-indigo-600 mb-6 font-bold transition-colors group"><Icon name="arrow-left" className="group-hover:-translate-x-1 transition-transform" />メインメニューに戻る</button><div className="bg-white rounded-[2.5rem] shadow-2xl overflow-hidden border border-slate-100"><div className={`${selectedTool.color} p-8 text-white`}><div className="flex items-center gap-4"><div className="bg-white/20 p-3 rounded-2xl"><Icon name={selectedTool.icon} className="w-8 h-8" /></div><h2 className="text-2xl font-bold">{selectedTool.title}</h2></div></div><div className="p-8 space-y-6">{selectedTool.id === 'youtube' ? (<div className="space-y-2"><label className="text-[10px] font-bold uppercase text-slate-400 ml-1">YouTube URL</label><inputtype="text"className="w-full p-4 bg-slate-50 border-2 border-slate-50 rounded-2xl focus:border-indigo-500 focus:bg-white outline-none transition-all"placeholder="https://www.youtube.com/watch?v=..."value={url}onChange={e => setUrl(e.target.value)}/></div>) : (<div className="space-y-2"><label className="text-[10px] font-bold uppercase text-slate-400 ml-1">ファイル選択</label><inputtype="file"multipleonChange={e => setFiles(Array.from(e.target.files))}className="w-full p-8 border-2 border-dashed border-slate-100 rounded-2xl text-center cursor-pointer hover:bg-slate-50 transition-colors"/>{files.length > 0 && (<div className="text-[10px] text-slate-400 mt-2 ml-1">選択済み: {files.length} 件のファイル</div>)}</div>)}{error && (<div className="p-4 bg-red-50 text-red-600 rounded-xl text-xs font-bold flex items-center gap-2 border border-red-100"><Icon name="alert-circle" /> {error}</div>)}{taskState.status !== 'idle' && (<div className="p-6 bg-slate-50 rounded-2xl space-y-3 border border-slate-100"><div className="flex justify-between items-end"><span className="text-[10px] font-bold text-slate-400 uppercase tracking-widest">Status: {taskState.status}</span><span className="text-xl font-black text-indigo-600">{taskState.progress}%</span></div><div className="h-2 bg-slate-200 rounded-full overflow-hidden"><div className="h-full bg-indigo-500 transition-all duration-500" style={{ width: `${taskState.progress}%` }}></div></div><div className="bg-slate-900 rounded-xl p-3 font-mono text-[9px] text-indigo-300">{taskState.logs.map((l, i) => <div key={i}>{`> ${l}`}</div>)}</div></div>)}<div className="flex gap-4 pt-4"><buttononClick={startProcessing}disabled={taskState.status === 'processing' || taskState.status === 'uploading'}className="flex-1 bg-slate-900 text-white py-4 rounded-2xl font-bold hover:bg-indigo-600 disabled:bg-slate-200 transition-all">処理開始</button>{downloadUrl && (<ahref={downloadUrl}className="flex-1 bg-emerald-500 text-white py-4 rounded-2xl font-bold text-center hover:bg-emerald-600 animate-pulse">ダウンロード</a>)}</div></div></div></div>)}</div></div>);}const root = ReactDOM.createRoot(document.getElementById('root'));root.render(<App />);7 unmodified lines891011121314151617181920212223242526272829303132333435363738394041421 unmodified line44454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961977 unmodified lines<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script><script src="https://unpkg.com/@babel/standalone/babel.min.js"></script><script src="https://cdn.tailwindcss.com"></script><script src="https://unpkg.com/lucide@latest"></script><style>@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }.animate-shake { animation: shake 0.2s ease-in-out 0s 2; }</style></head><body class="bg-[#FDFDFF] text-slate-900 font-sans"><div id="root"></div><script type="text/babel">const { useState, useEffect, useRef } = React;const Icon = ({ name, className = "" }) => {useEffect(() => { if (window.lucide) window.lucide.createIcons(); }, [name]);return <i data-lucide={name} className={className}></i>;};const TOOLS = [{ id: 'heic-jpg', title: 'HEIC → JPG', icon: 'image', color: 'bg-blue-500', description: 'iPhoneの写真を一般的な形式に変換' },{ id: 'm4a-mp3', title: 'M4A → MP3', icon: 'mic', color: 'bg-purple-500', description: '録音データをMP3に圧縮変換' },{ id: 'mp4-mp3', title: 'MP4 → MP3', icon: 'video', color: 'bg-red-500', description: '動画から音声のみを抽出' },{ id: 'jpeg-pdf', title: 'JPEG → PDF', icon: 'file-text', color: 'bg-green-500', description: '複数の画像を1つのPDFに結合' },{ id: 'pdf-png', title: 'PDF → PNG', icon: 'copy', color: 'bg-orange-500', description: 'PDFを画像として保存' },{ id: 'youtube', title: 'YouTube保存', icon: 'youtube', color: 'bg-rose-600', description: 'URLから動画をダウンロード' },];const App = () => {const [currentPage, setCurrentPage] = useState('main');const [selectedTool, setSelectedTool] = useState(null);const [isYoutubeEnabled, setIsYoutubeEnabled] = useState(false);const [taskState, setTaskState] = useState({ id: null, status: 'idle', progress: 0, logs: [] });const [files, setFiles] = useState([]);const [url, setUrl] = useState('');1 unmodified lineconst [downloadUrl, setDownloadUrl] = useState(null);const pollInterval = useRef(null);useEffect(() => {// バックエンドから設定(YouTubeが有効か)を取得fetch('/api/config').then(res => res.json()).then(data => setIsYoutubeEnabled(data.youtube_enabled)).catch(() => setIsYoutubeEnabled(false));}, []);const addLog = (msg) => {setTaskState(prev => ({ ...prev, logs: [...prev.logs.slice(-4), msg] }));};const resetState = () => {setTaskState({ id: null, status: 'idle', progress: 0, logs: [] });setFiles([]);setUrl('');setError('');setDownloadUrl(null);if (pollInterval.current) clearInterval(pollInterval.current);};const startProcessing = async () => {setTaskState({ id: null, status: 'uploading', progress: 10, logs: ['アップロードを開始します...'] });setError('');try {const formData = new FormData();formData.append('tool_id', selectedTool.id);if (selectedTool.id === 'youtube') {if (!url) throw new Error("URLを入力してください");formData.append('url', url);} else {if (files.length === 0) throw new Error("ファイルを選択してください");files.forEach(f => formData.append('files', f));}const res = await fetch('/api/convert', { method: 'POST', body: formData });const data = await res.json();if (!res.ok) throw new Error(data.error || "送信失敗");const taskId = data.task_id;setTaskState(prev => ({ ...prev, id: taskId, status: 'processing', progress: 20 }));pollInterval.current = setInterval(async () => {const sRes = await fetch(`/api/status/${taskId}`);const sData = await sRes.json();if (sData.status === 'completed') {clearInterval(pollInterval.current);setTaskState(prev => ({ ...prev, status: 'completed', progress: 100 }));setDownloadUrl(`/api/download/${taskId}`);} else if (sData.status === 'failed') {clearInterval(pollInterval.current);setError(sData.error || "処理失敗");setTaskState(prev => ({ ...prev, status: 'failed' }));} else {setTaskState(prev => ({ ...prev, progress: sData.progress || prev.progress }));if (sData.last_log) addLog(sData.last_log);}}, 2000);} catch (err) {setError(err.message);setTaskState(prev => ({ ...prev, status: 'idle' }));}};return (<div className="max-w-5xl mx-auto p-4 md:p-8">{currentPage === 'main' ? (<div><header className="text-center mb-16 pt-10"><h1 className="text-5xl font-black text-slate-900 mb-4 italic">MediaMaster <span className="text-indigo-600 not-italic">Async</span></h1><p className="text-slate-400 font-medium">高速・非同期メディア変換ツール</p></header><div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">{TOOLS.map(tool => (<div key={tool.id} onClick={() => { setSelectedTool(tool); setCurrentPage('tool'); resetState(); }} className="group bg-white p-8 rounded-[2rem] shadow-sm hover:shadow-xl transition-all border border-slate-100 cursor-pointer relative overflow-hidden"><div className={`${tool.color} w-12 h-12 rounded-2xl flex items-center justify-center mb-6 text-white group-hover:rotate-12 transition-transform shadow-md`}><Icon name={tool.icon} /></div><h3 className="text-xl font-bold text-slate-800 mb-2">{tool.title}</h3><p className="text-slate-400 text-sm font-medium">{tool.description}</p>{tool.id === 'youtube' && !isYoutubeEnabled && (<span className="absolute top-4 right-4 bg-slate-100 text-slate-400 px-3 py-1 rounded-full text-[10px] font-black">メンテナンス中</span>)}</div>))}</div></div>) : (<div className="max-w-2xl mx-auto"><button onClick={() => { if (pollInterval.current) clearInterval(pollInterval.current); setCurrentPage('main'); }} className="flex items-center gap-2 text-slate-400 hover:text-indigo-600 mb-8 font-black transition-all group"><Icon name="arrow-left" className="group-hover:-translate-x-1 transition-transform" /> BACK TO HUB</button><div className="bg-white rounded-[2.5rem] shadow-2xl border border-slate-50 overflow-hidden"><div className={`${selectedTool.color} p-8 text-white flex items-center gap-5`}><div className="bg-white/20 p-4 rounded-2xl"><Icon name={selectedTool.icon} className="w-8 h-8" /></div><h2 className="text-2xl font-black tracking-tight">{selectedTool.title}</h2></div><div className="p-10 space-y-8">{selectedTool.id === 'youtube' && !isYoutubeEnabled ? (<div className="text-center py-10 space-y-4"><div className="bg-amber-50 text-amber-600 p-6 rounded-3xl border border-amber-100"><Icon name="alert-triangle" className="w-12 h-12 mx-auto mb-4" /><h3 className="text-lg font-bold italic">YouTube��存機能は現在メンテナンス中です</h3><p className="text-sm opacity-80 mt-2">管理者によって外部サーバーが起動されるまでお待ちください。<br/>他の変換機能は通常通りご利用いただけます。</p></div></div>) : (<>{selectedTool.id === 'youtube' ? (<input type="text" placeholder="https://www.youtube.com/watch?v=..." className="w-full px-6 py-4 bg-slate-50 border-2 border-slate-100 rounded-2xl focus:border-indigo-500 outline-none transition-all" value={url} onChange={(e) => setUrl(e.target.value)} />) : (<div onClick={() => document.getElementById('fileIn').click()} className="border-2 border-dashed border-slate-100 bg-slate-50 rounded-[2rem] p-10 flex flex-col items-center justify-center cursor-pointer hover:bg-white transition-all"><input type="file" id="fileIn" multiple hidden onChange={(e) => setFiles(Array.from(e.target.files))} /><Icon name="upload" className="text-slate-300 mb-3 w-8 h-8" /><p className="text-slate-500 font-bold text-sm">クリックしてファイルを選択</p><div className="mt-4 flex flex-wrap gap-2">{files.map((f, i) => <span key={i} className="bg-white px-3 py-1 rounded-full text-[10px] font-bold border border-slate-100">{f.name}</span>)}</div></div>)}{error && <div className="p-4 bg-rose-50 text-rose-600 rounded-2xl text-xs font-bold flex items-center gap-3 border border-rose-100 animate-shake"><Icon name="alert-circle" />{error}</div>}{taskState.status !== 'idle' && (<div className="space-y-4 p-6 bg-slate-50 rounded-3xl border border-slate-100"><div className="flex justify-between font-black text-[10px] uppercase text-slate-400"><span>Status: {taskState.status}</span><span className="text-indigo-600 text-lg">{taskState.progress}%</span></div><div className="h-2 bg-slate-200 rounded-full overflow-hidden"><div className={`h-full ${selectedTool.color} transition-all duration-500`} style={{ width: `${taskState.progress}%` }}></div></div><div className="bg-slate-900 rounded-xl p-4 font-mono text-[9px] text-indigo-300/80">{taskState.logs.map((l, i) => <div key={i}>{`> ${l}`}</div>)}</div></div>)}<div className="flex flex-col sm:flex-row gap-4"><button onClick={startProcessing} disabled={taskState.status !== 'idle' && taskState.status !== 'completed' && taskState.status !== 'failed'} className="flex-1 bg-slate-900 text-white py-4 rounded-2xl font-black text-sm hover:bg-indigo-600 disabled:bg-slate-100 disabled:text-slate-400 transition-all">{taskState.status === 'processing' ? '処理実行中...' : 'START CONVERSION'}</button>{downloadUrl && (<a href={downloadUrl} className="flex-1 bg-emerald-500 text-white py-4 rounded-2xl font-black text-sm flex items-center justify-center gap-2 hover:bg-emerald-600 shadow-lg shadow-emerald-100"><Icon name="download" /> DOWNLOAD ZIP</a>)}</div></>)}</div></div></div>)}</div>);};const root = ReactDOM.createRoot(document.getElementById('root'));root.render(<App />);
index.html+126-162