import{bo as p,C as m,cQ as u,aT as S,aV as i,aU as y,cr as g,ce as l,bn as U}from"./index-lOezWVmi.js";const d=["can_delete","can_edit","can_manage_snapshots","can_manage_backups"],C=async(t,n,e)=>{const a=new URLSearchParams;return a.set("recursion","2"),a.set("project",n),l(a,e,d),fetch(`/1.0/storage-pools/${encodeURIComponent(t)}/volumes?${a.toString()}`).then(m).then(o=>o.metadata.map(s=>({...s,pool:t})))},f=async(t,n)=>{const e=new URLSearchParams;return e.set("recursion","1"),e.set("project",t),l(e,n,d),fetch(`/1.0/storage-volumes?${e.toString()}`).then(m).then(a=>a.metadata)},I=async(t,n,e,a,o,s)=>{const r=new URLSearchParams;return r.set("recursion","1"),r.set("project",n),p(r,o),l(r,s,d),fetch(`/1.0/storage-pools/${encodeURIComponent(t)}/volumes/${encodeURIComponent(e)}/${encodeURIComponent(a)}?${r.toString()}`).then(U).then(c=>({...c,pool:t}))},P=async(t,n,e,a,o)=>{const s=new URLSearchParams;return s.set("project",n),s.set("recursion","1"),p(s,o),fetch(`/1.0/storage-pools/${encodeURIComponent(t)}/volumes/${encodeURIComponent(e)}/${encodeURIComponent(a)}/state?${s.toString()}`).then(m).then(r=>r.metadata)},j=async(t,n,e,a=null)=>{const o=new URLSearchParams;return o.set("project",t),p(o,a),fetch(`/1.0/storage-pools/${encodeURIComponent(n.pool)}/volumes/${encodeURIComponent(n.type)}/${encodeURIComponent(n.name)}?${o.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})}).then(m).then(s=>s)},T=async(t,n,e,a,o,s)=>{const r=new URLSearchParams;return r.set("project",a),g.post(`/1.0/storage-pools/${encodeURIComponent(t)}/volumes/custom?${r.toString()}`,n,{headers:{"Content-Type":"application/octet-stream","X-Incus-name":e,"X-Incus-type":"iso"},onUploadProgress:c=>{o({percentage:c.progress?Math.floor(c.progress*100):0,loaded:c.loaded,total:c.total})},signal:s.signal}).then(c=>c.data)},V=async(t,n,e,a)=>{const o=new URLSearchParams;return o.set("project",n),p(o,a),fetch(`/1.0/storage-pools/${encodeURIComponent(t)}/volumes?${o.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(m).then(s=>s)},w=(t,n,e)=>{const a=new URLSearchParams;return a.set("project",t),p(a,e),new Promise((o,s)=>{fetch(`/1.0/storage-pools/${encodeURIComponent(n.pool)}/volumes?${a.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n.name,type:"custom",content_type:n.content_type,source:{name:n.name,type:"copy",pool:n.pool,volume_only:!1,refresh:!1,refresh_exclude_older:!1,location:n.location}})}).then(m).then(o).catch(s)})},L=async(t,n,e,a)=>{const o=new URLSearchParams;return o.set("project",n),p(o,a),fetch(`/1.0/storage-pools/${encodeURIComponent(t)}/volumes/${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}?${o.toString()}`,{method:"PUT",body:JSON.stringify(e),headers:{"Content-Type":"application/json","If-Match":e.etag??"invalid-etag"}}).then(m).then(s=>s)},R=async(t,n,e,a)=>{const o=new URLSearchParams;return o.set("project",e),p(o,a),fetch(`/1.0/storage-pools/${encodeURIComponent(n)}/volumes/custom/${encodeURIComponent(t)}?${o.toString()}`,{method:"DELETE"}).then(m).then(s=>s)},O=async(t,n)=>{const e=[];return new Promise((a,o)=>{Promise.allSettled(t.map(async s=>{const r={name:s.name,type:"volume",href:u(s)};return R(s.name,s.pool,n,s.location).then(()=>{S(e,r),i(e,t.length,a)}).catch(c=>{y(e,c instanceof Error?c.message:"",r),i(e,t.length,a)})})).catch(o)})},b=async(t,n,e,a)=>{const o=new URLSearchParams;return o.set("project",e),p(o,a),fetch(`/1.0/storage-pools/${encodeURIComponent(t.pool)}/volumes/custom/${encodeURIComponent(t.name)}?${o.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t.name,pool:n})}).then(m).then(s=>s)},_=async(t,n,e,a)=>{const o=new URLSearchParams;return e&&o.append("project",e),p(o,a),fetch(`/1.0/storage-pools/${encodeURIComponent(n)}/volumes/custom?${o.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then(m).then(s=>s)},E=async(t,n)=>{const e=new URLSearchParams;return e.set("project",t.project),p(e,t.location),fetch(`/1.0/storage-pools/${encodeURIComponent(t.pool)}/volumes/${encodeURIComponent(t.type)}/${encodeURIComponent(t.name)}/backups?${e.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:n}).then(m).then(a=>a)},k=async(t,n,e,a,o,s,r)=>{const c=new URLSearchParams;return c.set("project",e),p(c,r),g.post(`/1.0/storage-pools/${encodeURIComponent(a)}/volumes/custom?${c.toString()}`,t,{headers:{"Content-Type":"application/octet-stream","X-Incus-name":n},onUploadProgress:h=>{o({percentage:h.progress?Math.floor(h.progress*100):0,loaded:h.loaded,total:h.total})},signal:s.signal}).then(h=>h.data)};export{T as a,C as b,V as c,I as d,O as e,f,P as g,R as h,w as i,E as j,_ as k,L as l,b as m,j as r,k as u};
