1 line
9.7 KiB
JavaScript
1 line
9.7 KiB
JavaScript
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[167],{8648:function(e,t,i){Promise.resolve().then(i.bind(i,2572))},2572:function(e,t,i){"use strict";i.r(t),i.d(t,{default:function(){return d}});var r=i(7437),n=i(2265),o=i(9376);function s(){let e=(0,o.useRouter)(),t=(0,o.useSearchParams)(),i=(0,n.useRef)(null),s=(0,n.useRef)(null),[d,l]=(0,n.useState)(null),[c,p]=(0,n.useState)(null),[u,f]=(0,n.useState)(!1),[x,g]=(0,n.useState)(0),[h,b]=(0,n.useState)(""),[v,m]=(0,n.useState)(""),[y,j]=(0,n.useState)(null),w=t.get("generationUuid"),[S,k]=(0,n.useState)(w),[R,B]=(0,n.useState)(!1);function E(e){e.preventDefault(),e.stopPropagation()}function P(e){let t=e.dataTransfer;(null==t?void 0:t.files.length)&&z(t.files[0])}function z(e){if(!["video/mp4","video/quicktime","video/x-msvideo","video/webm"].includes(e.type)){m("Недопустимый тип файла. Разрешены: MP4, MOV, AVI, WebM");return}if(e.size>524288e3){m("Файл слишком большой. Максимум: 500MB");return}l(e),p(URL.createObjectURL(e)),m(""),j(null)}async function C(){try{let e=await T();j(e)}catch(e){}}async function T(){if(!d)throw Error("Файл не выбран");if(!S)throw Error("generationUuid не получен");f(!0),g(0),m(""),b("Загрузка видео...");try{let e=await M(),t=new FormData;return t.append("file",d),t.append("generationUuid",S),new Promise((i,r)=>{let n=new XMLHttpRequest;n.upload.addEventListener("progress",e=>{if(e.lengthComputable){let t=Math.round(e.loaded/e.total*100);g(t),b("Загрузка видео... ".concat(t,"%"))}}),n.addEventListener("load",()=>{if(201===n.status){let e=JSON.parse(n.responseText);g(100),b("Видео загружено"),f(!1),i(e.data.s3Key)}else{let e="Ошибка загрузки видео";try{e=JSON.parse(n.responseText).message||e}catch(e){}r(Error(e))}}),n.addEventListener("error",()=>{r(Error("Ошибка сети при загрузке"))}),n.open("POST","/api/upload/video"),n.setRequestHeader("x-csrf-token",e),n.withCredentials=!0,n.send(t)})}catch(e){throw m(e instanceof Error?e.message:"Ошибка загрузки"),f(!1),e}}async function U(){m("");try{if(!S)throw Error("generationUuid не получен");let t=y;t||(f(!0),b("Загрузка видео..."),t=await T(),j(t),f(!1)),b("Видео отправлено на обработку");let i=await M(),r={input:{url:t}},n=await fetch("/api/scenario/uniqueizer/step/1",{method:"POST",headers:{"Content-Type":"application/json","x-csrf-token":i},credentials:"same-origin",body:JSON.stringify(r)});if(!n.ok){let e=await n.json();throw Error(e.message||"Ошибка выполнения шага")}setTimeout(()=>{e.push("/result?generationUuid=".concat(S))},1e3)}catch(e){m(e instanceof Error?e.message:"Ошибка обработки"),f(!1)}}async function M(){let e=await fetch("/api/auth/csrf",{credentials:"same-origin"});return(await e.json()).csrfToken||""}return(0,n.useEffect)(()=>{let e=t.get("generationUuid");e?(k(e),B(!0),b("Сценарий запущен")):m("generationUuid не указан. Вернитесь на дашборд и запустите сценарий.")},[t]),(0,n.useEffect)(()=>{let e=s.current;e&&(["dragenter","dragover","dragleave","drop"].forEach(t=>{e.addEventListener(t,E,!1)}),["dragenter","dragover"].forEach(t=>{e.addEventListener(t,()=>e.classList.add("dragover"),!1)}),["dragleave","drop"].forEach(t=>{e.addEventListener(t,()=>e.classList.remove("dragover"),!1)}),e.addEventListener("drop",P,!1))},[]),(0,r.jsx)("div",{style:a.page,children:(0,r.jsx)("div",{style:a.container,children:(0,r.jsxs)("div",{style:a.card,children:[(0,r.jsx)("h1",{style:a.title,children:"Уникализация видео"}),v&&(0,r.jsx)("div",{style:a.error,children:v}),h&&(0,r.jsx)("div",{style:a.status,children:(0,r.jsx)("span",{children:h})}),!R&&(0,r.jsxs)("div",{style:a.infoBox,children:[(0,r.jsx)("span",{style:a.spinner}),"Запуск сценария..."]}),R&&!v&&(0,r.jsxs)("div",{style:a.infoBox,children:["✓ Сценарий запущен (ID: ",null==S?void 0:S.slice(0,8),"...)"]}),(0,r.jsxs)("div",{style:a.section,children:[(0,r.jsx)("h2",{style:a.sectionTitle,children:"1. Загрузите видео"}),d?(0,r.jsxs)("div",{style:a.filePreview,children:[(0,r.jsx)("video",{src:c,controls:!0,style:a.previewVideo}),(0,r.jsxs)("div",{style:a.filePreviewInfo,children:[(0,r.jsx)("div",{style:a.filePreviewName,children:d.name}),(0,r.jsx)("div",{children:function(e){if(0===e)return"0 Bytes";let t=Math.floor(Math.log(e)/Math.log(1024));return Math.round(e/Math.pow(1024,t)*100)/100+" "+["Bytes","KB","MB","GB"][t]}(d.size)})]}),(0,r.jsx)("button",{type:"button",onClick:function(){l(null),p(null),j(null),i.current&&(i.current.value="")},style:a.fileRemove,disabled:u,children:"\xd7"})]}):(0,r.jsxs)("div",{ref:s,style:a.fileUpload,onClick:()=>{var e;return null===(e=i.current)||void 0===e?void 0:e.click()},children:[(0,r.jsx)("input",{ref:i,type:"file",accept:"video/mp4,video/quicktime,video/x-msvideo,video/webm",onChange:function(e){var t;(null===(t=e.target.files)||void 0===t?void 0:t.length)&&z(e.target.files[0])},style:{display:"none"}}),(0,r.jsx)("div",{style:a.fileUploadIcon,children:"\uD83C\uDFAC"}),(0,r.jsx)("div",{style:a.fileUploadText,children:"Нажмите для загрузки или перетащите файл"}),(0,r.jsx)("div",{style:a.fileUploadHint,children:"MP4, MOV, AVI, WebM до 500MB"})]}),d&&!y&&(0,r.jsxs)("div",{children:[u&&x>0&&(0,r.jsxs)("div",{style:a.progressContainer,children:[(0,r.jsx)("div",{style:{...a.progressBar,width:"".concat(x,"%")}}),(0,r.jsxs)("span",{style:a.progressText,children:[x,"%"]})]}),(0,r.jsx)("button",{onClick:C,disabled:u||!R,style:{...a.btn,...a.btnPrimary,...u||!R?a.btnDisabled:{}},children:u?"Загрузка...":"Загрузить видео"})]})]}),(y||d)&&(0,r.jsxs)("div",{style:a.section,children:[(0,r.jsx)("h2",{style:a.sectionTitle,children:"2. Уникализируйте"}),(0,r.jsx)("p",{style:a.sectionDesc,children:"После нажатия видео будет отправлено на обработку"}),(0,r.jsx)("button",{onClick:U,disabled:u||!R,style:{...a.btn,...a.btnPrimary,...u||!R?a.btnDisabled:{}},children:u?"Загрузка...":"Уникализировать"})]}),(0,r.jsx)("button",{onClick:function(){e.push("/dashboard")},style:a.btnSecondary,children:"Закрыть"})]})})})}let a={page:{minHeight:"100vh",background:"#f5f5f5",display:"flex",alignItems:"center",justifyContent:"center",padding:"40px 20px"},container:{maxWidth:"700px",width:"100%"},emptyState:{textAlign:"center",padding:"60px 20px",color:"#666",fontSize:"16px"},card:{background:"white",padding:"40px",borderRadius:"8px",boxShadow:"0 2px 10px rgba(0,0,0,0.1)"},title:{fontSize:"24px",fontWeight:600,marginBottom:"24px",color:"#333",textAlign:"center"},infoBox:{display:"flex",alignItems:"center",gap:"10px",padding:"12px",background:"#e8f5e9",color:"#2e7d32",borderRadius:"6px",marginBottom:"20px",fontSize:"14px"},section:{marginBottom:"32px",padding:"20px",background:"#f8f9fa",borderRadius:"8px"},sectionTitle:{fontSize:"16px",fontWeight:600,color:"#333",marginBottom:"8px"},sectionDesc:{fontSize:"14px",color:"#666",marginBottom:"16px"},fileUpload:{border:"2px dashed #ddd",borderRadius:"8px",padding:"40px 20px",textAlign:"center",cursor:"pointer",transition:"all 0.2s"},fileUploadIcon:{fontSize:"48px",marginBottom:"16px"},fileUploadText:{fontSize:"16px",color:"#666",marginBottom:"8px"},fileUploadHint:{fontSize:"13px",color:"#999"},filePreview:{position:"relative",marginBottom:"16px"},previewVideo:{width:"100%",maxHeight:"400px",borderRadius:"8px",background:"#000"},filePreviewInfo:{padding:"12px",background:"#fff",borderRadius:"6px",marginTop:"8px",fontSize:"14px",color:"#666"},filePreviewName:{fontWeight:500,color:"#333",marginBottom:"4px"},fileRemove:{position:"absolute",top:"8px",right:"8px",background:"rgba(220, 38, 38, 0.9)",color:"white",border:"none",borderRadius:"50%",width:"32px",height:"32px",fontSize:"20px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},btn:{width:"100%",padding:"14px 24px",borderRadius:"6px",fontSize:"15px",fontWeight:500,cursor:"pointer",border:"none",transition:"all 0.2s"},btnPrimary:{background:"#007bff",color:"white"},btnDisabled:{background:"#ccc",cursor:"not-allowed"},btnSecondary:{width:"100%",padding:"12px 24px",background:"#f5f5f5",color:"#333",border:"1px solid #ddd",borderRadius:"6px",fontSize:"14px",fontWeight:500,cursor:"pointer"},error:{background:"#fee",color:"#c00",padding:"12px",borderRadius:"6px",marginBottom:"20px",fontSize:"14px"},status:{display:"flex",alignItems:"center",gap:"10px",padding:"12px",background:"#e7f3ff",color:"#0066cc",borderRadius:"6px",marginBottom:"20px",fontSize:"14px"},spinner:{display:"inline-block",width:"16px",height:"16px",border:"2px solid rgba(0,123,255,0.3)",borderTopColor:"#007bff",borderRadius:"50%",animation:"spin 1s linear infinite"},progressContainer:{position:"relative",height:"24px",background:"#e0e0e0",borderRadius:"12px",marginBottom:"12px",overflow:"hidden"},progressBar:{height:"100%",background:"linear-gradient(90deg, #007bff, #0056b3)",borderRadius:"12px",transition:"width 0.3s ease"},progressText:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",color:"#333"}};function d(){return(0,r.jsx)(n.Suspense,{fallback:(0,r.jsx)("div",{style:a.page,children:(0,r.jsx)("div",{style:a.container,children:(0,r.jsx)("div",{style:a.emptyState,children:"Загрузка..."})})}),children:(0,r.jsx)(s,{})})}},9376:function(e,t,i){"use strict";var r=i(5475);i.o(r,"useRouter")&&i.d(t,{useRouter:function(){return r.useRouter}}),i.o(r,"useSearchParams")&&i.d(t,{useSearchParams:function(){return r.useSearchParams}})}},function(e){e.O(0,[971,117,744],function(){return e(e.s=8648)}),_N_E=e.O()}]); |