Files
2026-05-13 14:20:41 +00:00

1 line
9.4 KiB
JavaScript

(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[681],{693:function(e,n,t){Promise.resolve().then(t.bind(t,1882))},1882:function(e,n,t){"use strict";t.r(n),t.d(n,{default:function(){return s}});var i=t(7437),r=t(2265),a=t(9376);function o(){let e=(0,a.useRouter)(),n=(0,a.useSearchParams)().get("scenario")||"nano-banana",t={"nano-banana":{name:"Nano Banana",desc:"Генерация изображений по промпту",icon:"\uD83C\uDFA8",class:"blue",stepId:"1"},"demo-scenario":{name:"Demo Scenario",desc:"Тестовый сценарий с подтверждением",icon:"\uD83E\uDDEA",class:"green",stepId:"collect-input"}},o=t[n]||t["nano-banana"],[s,l]=(0,r.useState)(""),[c,p]=(0,r.useState)(null),[u,f]=(0,r.useState)(null),[x,g]=(0,r.useState)(""),[h,m]=(0,r.useState)(!1),[b,y]=(0,r.useState)(""),[v,j]=(0,r.useState)(""),S=(0,r.useRef)(null),w=(0,r.useRef)(null);async function k(){try{let e=await fetch("/api/auth/csrf",{credentials:"same-origin"}),n=await e.json();j(n.csrfToken||"")}catch(e){console.error("Failed to load CSRF token:",e)}}function P(e){e.preventDefault(),e.stopPropagation()}function R(e){let n=e.dataTransfer;(null==n?void 0:n.files.length)&&I(n.files[0])}function I(e){if(!["image/jpeg","image/jpg","image/png","image/gif","image/webp"].includes(e.type)){g("Недопустимый тип файла. Разрешены: JPEG, PNG, GIF, WebP");return}if(e.size>10485760){g("Файл слишком большой. Максимум: 10MB");return}p(e);let n=new FileReader;n.onload=e=>{var n;return f(null===(n=e.target)||void 0===n?void 0:n.result)},n.readAsDataURL(e),g("")}async function E(e,n,t){let i=new FormData;i.append("file",e),i.append("generationUuid",n),i.append("generationStepId",t);let r=await fetch("/api/upload/image",{method:"POST",headers:{"x-csrf-token":v},body:i,credentials:"same-origin"}),a=await r.json();if(!r.ok)throw Error(a.message||"Ошибка загрузки файла");return a.data.s3Key}async function C(t){t.preventDefault(),m(!0),g(""),y("Запуск сценария...");try{let t;let i=await fetch("/api/scenario/".concat(n,"/start"),{method:"POST",headers:{"Content-Type":"application/json","x-csrf-token":v},credentials:"same-origin",body:JSON.stringify({})}),r=await i.json();if(!i.ok)throw Error(r.message||"Ошибка запуска сценария");let a=r.generationUuid;if(c){y("Загрузка файла...");let e=await fetch("/api/scenario/".concat(n,"/step/").concat(o.stepId,"/record"),{method:"POST",headers:{"Content-Type":"application/json","x-csrf-token":v},credentials:"same-origin",body:JSON.stringify({prompt:s})}),i=(await e.json()).stepRecordId;t=await E(c,a,i)}let d={prompt:s};t&&(d.imageKey=t),y("Генерация...");let l=await fetch("/api/scenario/".concat(n,"/step/").concat(o.stepId),{method:"POST",headers:{"Content-Type":"application/json","x-csrf-token":v},credentials:"same-origin",body:JSON.stringify(d)}),p=await l.json();if(!l.ok)throw Error(p.message||"Ошибка выполнения шага");e.push("/result?generationUuid=".concat(a))}catch(e){g(e instanceof Error?e.message:"Неизвестная ошибка"),m(!1),y("")}}return(0,r.useEffect)(()=>{k(),function(){let e=w.current;e&&(["dragenter","dragover","dragleave","drop"].forEach(n=>{e.addEventListener(n,P,!1)}),["dragenter","dragover"].forEach(n=>{e.addEventListener(n,()=>e.classList.add("dragover"),!1)}),["dragleave","drop"].forEach(n=>{e.addEventListener(n,()=>e.classList.remove("dragover"),!1)}),e.addEventListener("drop",R,!1))}()},[]),(0,i.jsx)("div",{style:d.page,children:(0,i.jsxs)("div",{style:d.container,children:[(0,i.jsxs)("div",{style:d.header,children:[(0,i.jsx)("h1",{style:d.headerTitle,children:"Создание"}),(0,i.jsx)("button",{onClick:()=>e.push("/dashboard"),style:d.btnSmall,children:"Назад"})]}),(0,i.jsxs)("div",{style:d.card,children:[(0,i.jsxs)("div",{style:d.scenarioInfo,children:[(0,i.jsx)("div",{style:{...d.scenarioIcon,...d[o.class]},children:o.icon}),(0,i.jsxs)("div",{children:[(0,i.jsx)("div",{style:d.scenarioName,children:o.name}),(0,i.jsx)("div",{style:d.scenarioDesc,children:o.desc})]})]}),x&&(0,i.jsx)("div",{style:d.error,children:x}),(0,i.jsxs)("form",{onSubmit:C,children:[(0,i.jsxs)("div",{style:d.formGroup,children:[(0,i.jsx)("label",{htmlFor:"prompt",style:d.label,children:"Опишите, что хотите создать"}),(0,i.jsx)("textarea",{id:"prompt",value:s,onChange:e=>l(e.target.value),required:!0,placeholder:"Например: кот в космосе, цифровая иллюстрация, яркие цвета...",style:d.textarea})]}),(0,i.jsxs)("div",{style:d.formGroup,children:[(0,i.jsx)("label",{style:d.label,children:"Изображение (опционально)"}),(0,i.jsxs)("div",{ref:w,style:d.fileUpload,onClick:()=>{var e;return null===(e=S.current)||void 0===e?void 0:e.click()},children:[(0,i.jsx)("input",{ref:S,type:"file",accept:"image/jpeg,image/jpg,image/png,image/gif,image/webp",onChange:function(e){var n;(null===(n=e.target.files)||void 0===n?void 0:n.length)&&I(e.target.files[0])},style:{display:"none"}}),(0,i.jsxs)("div",{style:d.fileUploadLabel,children:[(0,i.jsx)("div",{style:d.fileUploadIcon,children:"\uD83D\uDCC1"}),(0,i.jsx)("div",{style:d.fileUploadText,children:"Нажмите для загрузки или перетащите файл"}),(0,i.jsx)("div",{style:{...d.fileUploadText,fontSize:"12px",color:"#999",marginTop:"4px"},children:"JPEG, PNG, GIF, WebP до 10MB"})]})]}),u&&(0,i.jsxs)("div",{style:d.filePreview,children:[(0,i.jsx)("img",{src:u,alt:"Preview",style:d.previewImg}),(0,i.jsxs)("div",{style:d.filePreviewInfo,children:[(0,i.jsx)("div",{style:d.filePreviewName,children:null==c?void 0:c.name}),(0,i.jsx)("div",{children:c&&function(e){if(0===e)return"0 Bytes";let n=Math.floor(Math.log(e)/Math.log(1024));return Math.round(e/Math.pow(1024,n)*100)/100+" "+["Bytes","KB","MB","GB"][n]}(c.size)})]}),(0,i.jsx)("button",{type:"button",onClick:function(){p(null),f(null),S.current&&(S.current.value="")},style:d.fileRemove,children:"\xd7"})]})]}),(0,i.jsx)("button",{type:"submit",disabled:h,style:{...d.btnPrimary,...h?d.btnDisabled:{}},children:h?"Запуск...":"Создать"})]}),b&&(0,i.jsxs)("div",{style:d.status,children:[(0,i.jsx)("span",{style:d.spinner}),(0,i.jsx)("span",{children:b})]})]})]})})}function s(){return(0,i.jsx)(r.Suspense,{fallback:(0,i.jsx)("div",{style:d.page,children:(0,i.jsx)("div",{style:d.container,children:(0,i.jsx)("div",{style:d.emptyState,children:"Загрузка..."})})}),children:(0,i.jsx)(o,{})})}let d={page:{minHeight:"100vh",padding:"40px 20px",background:"#f5f5f5"},container:{maxWidth:"600px",margin:"0 auto"},emptyState:{textAlign:"center",padding:"60px 20px",color:"#666"},header:{background:"white",padding:"20px 30px",borderRadius:"8px",boxShadow:"0 2px 10px rgba(0,0,0,0.1)",marginBottom:"20px",display:"flex",justifyContent:"space-between",alignItems:"center"},headerTitle:{fontSize:"20px",fontWeight:600,color:"#333"},btnSmall:{background:"none",border:"1px solid #ddd",padding:"8px 16px",borderRadius:"6px",cursor:"pointer",fontSize:"14px",color:"#666"},card:{background:"white",padding:"30px",borderRadius:"8px",boxShadow:"0 2px 10px rgba(0,0,0,0.1)"},scenarioInfo:{display:"flex",alignItems:"center",gap:"12px",marginBottom:"24px",padding:"16px",background:"#f8f9fa",borderRadius:"6px"},scenarioIcon:{width:"40px",height:"40px",borderRadius:"8px",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"20px"},blue:{background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)"},green:{background:"linear-gradient(135deg, #11998e 0%, #38ef7d 100%)"},scenarioName:{fontWeight:600,color:"#333"},scenarioDesc:{fontSize:"13px",color:"#666"},formGroup:{marginBottom:"20px"},label:{display:"block",marginBottom:"8px",fontSize:"14px",color:"#333",fontWeight:500},textarea:{width:"100%",padding:"14px",border:"1px solid #ddd",borderRadius:"6px",fontSize:"14px",fontFamily:"inherit",resize:"vertical",minHeight:"120px"},fileUpload:{border:"2px dashed #ddd",borderRadius:"6px",padding:"20px",textAlign:"center",cursor:"pointer",transition:"all 0.2s",marginBottom:"10px"},fileUploadLabel:{display:"block",cursor:"pointer"},fileUploadIcon:{fontSize:"32px",marginBottom:"8px"},fileUploadText:{fontSize:"14px",color:"#666"},filePreview:{display:"flex",alignItems:"center",gap:"10px",marginTop:"10px",padding:"10px",background:"#f8f9fa",borderRadius:"6px"},previewImg:{maxWidth:"80px",maxHeight:"80px",borderRadius:"4px",objectFit:"cover"},filePreviewInfo:{flex:1,fontSize:"13px",color:"#666"},filePreviewName:{fontWeight:500,color:"#333",marginBottom:"4px"},fileRemove:{background:"none",border:"none",color:"#dc3545",cursor:"pointer",fontSize:"18px",padding:"4px 8px"},btnPrimary:{padding:"12px 24px",background:"#007bff",color:"white",border:"none",borderRadius:"6px",fontSize:"14px",fontWeight:500,cursor:"pointer",width:"100%"},btnDisabled:{background:"#ccc",cursor:"not-allowed"},error:{background:"#fee",color:"#c00",padding:"12px",borderRadius:"6px",marginBottom:"20px",fontSize:"14px"},status:{textAlign:"center",padding:"20px",color:"#666"},spinner:{display:"inline-block",width:"20px",height:"20px",border:"2px solid #ddd",borderTopColor:"#007bff",borderRadius:"50%",animation:"spin 1s linear infinite",marginRight:"10px",verticalAlign:"middle"}}},9376:function(e,n,t){"use strict";var i=t(5475);t.o(i,"useRouter")&&t.d(n,{useRouter:function(){return i.useRouter}}),t.o(i,"useSearchParams")&&t.d(n,{useSearchParams:function(){return i.useSearchParams}})}},function(e){e.O(0,[971,117,744],function(){return e(e.s=693)}),_N_E=e.O()}]);