seedance 적용.
This commit is contained in:
1 parent
4deefff061
commit
154bf5b992
18 files changed
+942
-179
No files matched your search
+83
-35
@@ -215,10 +215,11 @@ const Icon = {
|
||||
};
|
||||
|
||||
/* ===== Config ===== */
|
||||
// 같은 출처(FastAPI가 이 페이지를 서빙)면 "" 로 두면 /api/generate 로 전송.
|
||||
// 백엔드 미연결 시 fetch 실패 → 자동으로 데모 결과로 폴백.
|
||||
const API_BASE = "";
|
||||
const DEMO_VIDEO = "./demo/mumum.mp4";
|
||||
// 백엔드 주소. 같은 출처(FastAPI가 이 페이지를 서빙)면 "" 로 두면 /api/generate 로 전송.
|
||||
// 프론트/백엔드를 분리 배포할 땐 빌드/배포 시점에 window.__API_BASE__ 를 head 에 주입
|
||||
// 예) window.__API_BASE__ = "https://api.example.com";
|
||||
// 생성 실패/서버 미연결 시 데모 영상은 표시하지 않고 에러 카드만 보여준다.
|
||||
const API_BASE = (typeof window !== "undefined" && window.__API_BASE__) || "";
|
||||
|
||||
const STEPS = [
|
||||
{ k:"setup", n:"1", b:"사진 업로드", s:"4~5장" },
|
||||
@@ -245,7 +246,8 @@ function App(){
|
||||
const [price, setPrice] = useState("");
|
||||
const [selling, setSelling] = useState(""); // 강력한 한방 셀링포인트
|
||||
const [prog, setProg] = useState([0,0,0]);
|
||||
const [videoUrl, setVideoUrl] = useState(DEMO_VIDEO);
|
||||
const [videoUrl, setVideoUrl] = useState(null); // 성공 시에만 채움 (데모 폴백 없음)
|
||||
const [errMsg, setErrMsg] = useState(""); // 생성 실패 메시지 (있으면 결과 화면이 에러 카드로 전환)
|
||||
const [srvCaption, setSrvCaption] = useState(null);
|
||||
const [srvProfile, setSrvProfile] = useState(null);
|
||||
const [editedCaption, setEditedCaption] = useState("");
|
||||
@@ -255,7 +257,10 @@ function App(){
|
||||
const [scriptEditing, setScriptEditing] = useState({});
|
||||
const [scriptLoading, setScriptLoading] = useState(false);
|
||||
const fileRef = useRef();
|
||||
const doneRef = useRef({ bars:false, fetch:false });
|
||||
const pollRef = useRef(null); // 진행 중인 폴링 타이머 (언마운트/리셋 시 정리)
|
||||
|
||||
// 언마운트 시 폴링 타이머 정리
|
||||
useEffect(()=>()=>{ if(pollRef.current) clearTimeout(pollRef.current); }, []);
|
||||
|
||||
// 톤 자동 매칭 (인텔리전스 IP를 가볍게 노출 — 유형 기반)
|
||||
const tone = kind === "product"
|
||||
@@ -282,29 +287,61 @@ function App(){
|
||||
}
|
||||
function removePhoto(i){ setPhotos(p=>p.filter((_,idx)=>idx!==i)); }
|
||||
|
||||
function finishIfReady(){
|
||||
if(doneRef.current.bars && doneRef.current.fetch) setStep("result");
|
||||
// 작업 상태(stage_index 0..2)를 3개 진행바 배열로 변환.
|
||||
// 이전 단계 = 100%, 현재 단계 = 진행 중(서버 progress 또는 점진 증가), 이후 단계 = 0%
|
||||
function barsForStatus(st, prevBars){
|
||||
const idx = st.stage_index || 0;
|
||||
return [0,1,2].map(i=>{
|
||||
if(st.status === "done") return 100;
|
||||
if(i < idx) return 100;
|
||||
if(i > idx) return 0;
|
||||
// 현재 진행 중인 바: 95%까지 조금씩 차오르게(완료 신호는 폴링이 줌)
|
||||
const cur = (prevBars && prevBars[i]) || 0;
|
||||
return Math.min(95, Math.max(cur + Math.round(Math.random()*8+4), 8));
|
||||
});
|
||||
}
|
||||
|
||||
function stopPolling(){ if(pollRef.current){ clearTimeout(pollRef.current); pollRef.current = null; } }
|
||||
|
||||
// 작업 완료/실패 시 결과 화면으로
|
||||
function finishWith(st){
|
||||
if(st.video_url) setVideoUrl((API_BASE||"") + st.video_url);
|
||||
if(st.caption){ setSrvCaption(st.caption); setEditedCaption(st.caption); }
|
||||
if(st.profile) setSrvProfile(st.profile);
|
||||
setProg([100,100,100]);
|
||||
setStep("result");
|
||||
}
|
||||
|
||||
// job_id 를 주기적으로 폴링하며 진행바를 갱신
|
||||
function pollJob(jobId){
|
||||
fetch(`${API_BASE}/api/jobs/${jobId}`)
|
||||
.then(r=> r.ok ? r.json() : Promise.reject(new Error("HTTP "+r.status)))
|
||||
.then(st=>{
|
||||
setProg(prev=> barsForStatus(st, prev));
|
||||
if(st.caption && !srvCaption){ setSrvCaption(st.caption); setEditedCaption(st.caption); }
|
||||
if(st.profile) setSrvProfile(st.profile);
|
||||
if(st.status === "done"){ finishWith(st); return; }
|
||||
if(st.status === "error"){
|
||||
// 실패 시 데모 영상 표시 안 함 — 에러 카드만 보여준다.
|
||||
setVideoUrl(null);
|
||||
setErrMsg(st.error || "알 수 없는 오류로 생성에 실패했습니다.");
|
||||
setProg([100,100,100]); setStep("result");
|
||||
return;
|
||||
}
|
||||
pollRef.current = setTimeout(()=>pollJob(jobId), 2000); // 2초 간격 폴링
|
||||
})
|
||||
.catch(()=>{ // 폴링 실패 → 잠시 후 재시도 (네트워크 일시 단절 대비)
|
||||
pollRef.current = setTimeout(()=>pollJob(jobId), 3000);
|
||||
});
|
||||
}
|
||||
|
||||
function startGenerate(){
|
||||
stopPolling();
|
||||
setStep("generating");
|
||||
setProg([0,0,0]); setNote(""); setSrvCaption(null); setCopied(false);
|
||||
setProg([6,0,0]); setNote(""); setErrMsg(""); setVideoUrl(null); setSrvCaption(null); setCopied(false);
|
||||
setSrvProfile(tone.profile);
|
||||
setEditedCaption(caption); // 로컬 폴백; 서버 응답 오면 교체
|
||||
doneRef.current = { bars:false, fetch:false };
|
||||
|
||||
// 진행 바 애니메이션 (시각용)
|
||||
[0,1,2].forEach((agent)=>{
|
||||
let p = 0; const base = agent*1600;
|
||||
const tick = ()=>{
|
||||
p += Math.random()*22+10; if(p>100) p=100;
|
||||
setProg(prev=>{ const n=[...prev]; n[agent]=Math.round(p); return n; });
|
||||
if(p<100) setTimeout(tick, 260);
|
||||
else if(agent===2){ doneRef.current.bars=true; finishIfReady(); }
|
||||
};
|
||||
setTimeout(tick, base+300);
|
||||
});
|
||||
|
||||
// 실제 생성 요청 (실패 시 데모 폴백)
|
||||
const fd = new FormData();
|
||||
fd.append("kind", kind);
|
||||
fd.append("biz_name", bizName);
|
||||
@@ -313,20 +350,20 @@ function App(){
|
||||
if(price) fd.append("price", price);
|
||||
photos.forEach(p=> p.file && fd.append("photos", p.file, p.name));
|
||||
|
||||
// 1) 작업 제출 → job_id 즉시 수신, 2) job_id 폴링
|
||||
fetch(`${API_BASE}/api/generate`, { method:"POST", body:fd })
|
||||
.then(r=> r.ok ? r.json() : Promise.reject(new Error("HTTP "+r.status)))
|
||||
.then(res=>{
|
||||
setVideoUrl((API_BASE||"") + res.video_url);
|
||||
if(res.caption){ setSrvCaption(res.caption); setEditedCaption(res.caption); }
|
||||
if(res.profile) setSrvProfile(res.profile);
|
||||
.then(st=>{
|
||||
if(!st.job_id) throw new Error("no job_id");
|
||||
pollJob(st.job_id);
|
||||
})
|
||||
.catch(()=>{
|
||||
setVideoUrl(DEMO_VIDEO);
|
||||
setNote("백엔드 미연결 — 데모 결과를 표시합니다. (서버 실행 시 실제 생성)");
|
||||
})
|
||||
.finally(()=>{ doneRef.current.fetch=true; finishIfReady(); });
|
||||
.catch(()=>{ // 서버 연결 실패 → 데모 안 띄우고 에러 카드
|
||||
setVideoUrl(null);
|
||||
setErrMsg("서버에 연결하지 못했습니다. 잠시 후 다시 시도해 주세요.");
|
||||
setProg([100,100,100]); setStep("result");
|
||||
});
|
||||
}
|
||||
function reset(){ setStep("setup"); setPhotos([]); setKind(""); setBizName(""); setAddr(""); setPrice(""); setSelling(""); setProg([0,0,0]); setNote(""); setSrvCaption(null); setSrvProfile(null); setEditedCaption(""); setCopied(false); setVideoUrl(DEMO_VIDEO); setScript(null); setScriptEditing({}); }
|
||||
function reset(){ stopPolling(); setStep("setup"); setPhotos([]); setKind(""); setBizName(""); setAddr(""); setPrice(""); setSelling(""); setProg([0,0,0]); setNote(""); setErrMsg(""); setSrvCaption(null); setSrvProfile(null); setEditedCaption(""); setCopied(false); setVideoUrl(null); setScript(null); setScriptEditing({}); }
|
||||
|
||||
function copyCaption(){
|
||||
navigator.clipboard.writeText(editedCaption).then(()=>{ setCopied(true); setTimeout(()=>setCopied(false), 1800); });
|
||||
@@ -549,8 +586,19 @@ function App(){
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* STEP 4 — RESULT */}
|
||||
{step==="result" && (
|
||||
{/* STEP 4 — RESULT (성공: 영상 / 실패: 에러 카드) */}
|
||||
{step==="result" && errMsg && (
|
||||
<div className="card">
|
||||
<h2 className="res-h">영상 생성에 실패했습니다</h2>
|
||||
<p className="res-sub">아래 사유를 확인하고 다시 시도해 주세요. (데모 영상은 표시하지 않습니다)</p>
|
||||
<div className="caption-box" style={{borderColor:"rgba(255,120,120,0.4)"}}>{errMsg}</div>
|
||||
<div className="res-actions">
|
||||
<button className="btn btn-primary" onClick={startGenerate}>다시 시도</button>
|
||||
<button className="btn btn-ghost" onClick={reset}>처음으로</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{step==="result" && !errMsg && videoUrl && (
|
||||
<div className="card">
|
||||
<div className="result-grid">
|
||||
<div className="phone">
|
||||
|
||||
Reference in new issue
Block a user