Your IP : 216.73.216.52


Current Path : /snap/lxd/38450/share/lxd-ui/assets/
Upload File :
Current File : //snap/lxd/38450/share/lxd-ui/assets/UploadCustomIso-C4mIsVip.js

import{j as e,d as t,E as O,v as P,S as U,r as o,s as z,a0 as j,x as S}from"./index-BsQN_SZU.js";import{P as B}from"./ProgressBar-CZqVHpuJ.js";import{S as L}from"./StoragePoolSelector-Bvqvds5t.js";import{a as Q}from"./storage-volumes-CG043sqG.js";const V=()=>e.jsx(e.Fragment,{children:e.jsx("div",{className:"p-notification--information",children:e.jsxs("div",{className:"p-notification__content",children:[e.jsx("h3",{className:"p-notification__title",children:"Some image formats need to be modified in order to work with LXD."}),e.jsx("p",{children:e.jsxs("a",{className:"p-notification__action",href:"https://ubuntu.com/tutorials/how-to-install-a-windows-11-vm-using-lxd#1-overview",target:"_blank",rel:"noopener noreferrer",children:["Windows ISO images",e.jsx(t.Icon,{className:"external-link-icon",name:"external-link"})]})})]})})}),q=n=>n.replace(/[^A-Za-z0-9.-]/g,"-"),v=n=>/^[A-Za-z0-9.-]+$/.test(n)||!n,M=({onCancel:n,onFinish:b})=>{const C=O(),N=P(),{project:I}=U(),[i,w]=o.useState(null),[r,h]=o.useState(""),[x,u]=o.useState(!1),[c,y]=o.useState(""),[a,m]=o.useState(null),[k,A]=o.useState(null),[p,d]=o.useState(null),g=I?.name??"",_=()=>{k?.abort(),n()},E=()=>{if(!i)return;d(null),u(!0);const s=new AbortController;A(s),Q(c,i,r,g,m,s).then(l=>{C.set(l.metadata.id,()=>{b(r,c)},f=>{d(t.failure("Custom ISO upload failed",new Error(f)))},()=>{u(!1),m(null),N.invalidateQueries({queryKey:[S.storage,c,S.volumes,g]})})}).catch(l=>{const f=new Error(l.response?.data.error);d(t.failure("Custom ISO upload failed",f)),u(!1),m(null)})},F=s=>{if(s.target.files){const l=s.target.files[0];w(l),h(q(l.name))}};return e.jsxs(e.Fragment,{children:[p?e.jsx(t.Notification,{title:p.title,severity:"negative",onDismiss:()=>{d(null)},children:p.message}):e.jsx(V,{}),e.jsxs("div",{className:z("custom-iso-form",{"u-hide":!!a}),children:[e.jsx(t.Input,{name:"iso",type:"file",id:"iso-image",label:"Local file",onChange:F,stacked:!0}),e.jsx(t.Input,{name:"name",type:"text",id:"name",label:"Alias",value:r,onChange:s=>{h(s.target.value)},disabled:i===null,error:r&&!v(r)?e.jsx("div",{className:"alias-error",children:"Only alphanumeric characters, periods or hyphens are allowed in this field"}):void 0,stacked:!0}),e.jsx(L,{value:c,setValue:y,selectProps:{id:"storagePool",label:"Storage pool",disabled:i===null,stacked:!0}})]}),a&&e.jsxs(e.Fragment,{children:[e.jsx(B,{percentage:Math.floor(a.percentage)}),e.jsxs("p",{children:[j(a.loaded)," loaded of"," ",j(a.total??0)]}),a.loaded===a.total&&e.jsx(t.Spinner,{className:"u-loader",text:"Validating ISO"})]}),e.jsxs("footer",{className:"p-modal__footer",children:[e.jsx(t.Button,{appearance:"base",onClick:_,className:"u-no-margin--bottom",children:"Back"}),e.jsx(t.ActionButton,{appearance:"positive",loading:x,disabled:!i||!v(r)||x,className:"u-no-margin--bottom",onClick:E,children:"Upload"})]})]})};export{M as U};