Files
AIGC/demo/deploy_baota/frontend/static/imageToVideo-6b02abdd.js

2 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

2025-11-13 17:01:39 +08:00
import{a as i}from"./index-2fb4354b.js";const p={createTask(t){if(!t)throw new Error("参数不能为空");if(!t.firstFrame)throw new Error("首帧图片不能为空");if(!t.prompt||t.prompt.trim()==="")throw new Error("描述文字不能为空");if(!t.aspectRatio)throw new Error("视频比例不能为空");if(!t.duration||t.duration<1||t.duration>60)throw new Error("视频时长必须在1-60秒之间");const e=new FormData;return e.append("firstFrame",t.firstFrame),e.append("prompt",t.prompt.trim()),e.append("aspectRatio",t.aspectRatio),e.append("duration",t.duration.toString()),e.append("hdMode",t.hdMode.toString()),t.lastFrame&&e.append("lastFrame",t.lastFrame),i({url:"/image-to-video/create",method:"POST",data:e,headers:{"Content-Type":"multipart/form-data"}})},getTasks(t=0,e=10){return i({url:"/image-to-video/tasks",method:"GET",params:{page:t,size:e}})},getTaskDetail(t){return i({url:`/image-to-video/tasks/${t}`,method:"GET"})},getTaskStatus(t){return i({url:`/image-to-video/tasks/${t}/status`,method:"GET"})},pollTaskStatus(t,e,n,a){let s=!0,u=0;const l=30,d=async()=>{if(!s||u>=l){u>=l&&a&&a(new Error("任务超时"));return}try{const o=await i({url:`/image-to-video/tasks/${t}/status`,method:"GET"});if(!o||!o.data||!o.data.success){a&&a(new Error("获取任务状态失败")),s=!1;return}const r=o.data.data;if(!r||!r.status){a&&a(new Error("无效的任务数据")),s=!1;return}if(r.status==="COMPLETED"){n&&n(r),s=!1;return}if(r.status==="FAILED"||r.status==="CANCELLED"){console.error("任务失败:",{taskId:t,status:r.status,errorMessage:r.errorMessage,pollCount:u}),a&&a(new Error(r.errorMessage||"任务失败")),s=!1;return}e&&e({status:r.status,progress:r.progress||0,resultUrl:r.resultUrl}),u++,setTimeout(d,12e4)}catch(o){console.error("轮询任务状态失败:",o),a&&a(o),s=!1}};return d(),()=>{s=!1}}};export{p as i};