Your IP : 216.73.216.189


Current Path : /proc/thread-self/root/snap/lxd/current/share/lxd-ui/assets/
Upload File :
Current File : //proc/thread-self/root/snap/lxd/current/share/lxd-ui/assets/useImages-DavKpFTt.js

import{R as d,az as h,aB as O,aC as j,aD as w,cR as q,cp as P,H as T,u as S,ae as f,K as A,T as v,w as b}from"./index-BFGypnt-.js";import{j as R,l as x,b as E}from"./images-C6WqBeZG.js";import{f as U,a as C}from"./image-registries-YAuyq4CZ.js";const L=["can_delete"],J=async(t,e)=>{const s=new URLSearchParams;return s.set("recursion","1"),s.set("project",t),P(s,e,L),fetch(`${d}/1.0/images?${s.toString()}`).then(h).then(a=>a.metadata)},K=async t=>{const e=new URLSearchParams;return e.set("recursion","1"),e.set("all-projects","1"),P(e,t,L),fetch(`${d}/1.0/images?${e.toString()}`).then(h).then(s=>s.metadata)},k=async(t,e)=>{const s=new URLSearchParams;return s.set("project",e),fetch(`${d}/1.0/images/${encodeURIComponent(t.fingerprint)}?${s.toString()}`,{method:"DELETE"}).then(h).then(a=>a)},W=async(t,e,s)=>{const a=[];return new Promise((n,o)=>{Promise.allSettled(t.map(async c=>{const p={fingerprint:c},m={name:c,type:"image",href:`${d}/ui/project/${encodeURIComponent(e)}/local-images`};return k(p,e).then(l=>{s.set(l.metadata.id,()=>{O(a,m)},y=>{j(a,y,m)},()=>{w(a,t.length,n)})}).catch(l=>{j(a,l instanceof Error?l.message:"",m),w(a,t.length,n)})})).catch(o)})},Y=async(t,e,s)=>{const a=new URLSearchParams;a.set("project",s),await fetch(`${d}/1.0/images/aliases?${a.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({target:t,name:e})}).then(h)},Z=async(t,e)=>{const s=new URLSearchParams;return s.set("project",e),fetch(`${d}/1.0/images?${s.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:t}).then(h).then(a=>a)},ee=async(t,e,s,a)=>{const n=new URLSearchParams;return n.set("project",a),q.post(`${d}/1.0/images?${n.toString()}`,t,{headers:{"Content-Type":"application/octet-stream","X-LXD-public":JSON.stringify(e)},onUploadProgress:o=>{s({percentage:o.progress?Math.floor(o.progress*100):0,loaded:o.loaded,total:o.total})}}).then(o=>o.data)},B="https://cloud-images.ubuntu.com/releases/streams/v1/com.ubuntu.cloud:released:download.json",D="https://cloud-images.ubuntu.com/releases",N="https://cloud-images.ubuntu.com/minimal/releases/streams/v1/com.ubuntu.cloud:released:download.json",_="https://cloud-images.ubuntu.com/minimal/releases/",z="https://images.lxd.canonical.com/streams/v1/images.json",G="https://images.lxd.canonical.com",H=async()=>{const t=await I(B,D),e=await I(N,_),s=await I(z,G),a=[...t.images].reverse().sort(R).concat([...e.images].reverse().sort(R)).concat([...s.images]),n=[t.error,e.error,s.error].filter(o=>o!=="");return{images:a,error:n.join(". ")}},I=async(t,e)=>new Promise(s=>{fetch(t).then(h).then(a=>{const n=Object.entries(a.products).map(o=>{const{os:c,...p}=o[1],m=T(c);return{...p,os:m,server:e}});s({images:n,error:""})}).catch(a=>{s({images:[],error:a.message})})}),X=async(t,e)=>{const s=await U(t),a=r=>e?.config.restricted?(e?.config["restricted.registries"]?.split(",")??[]).includes(r.name):!0,n={},o=await Promise.allSettled(s.filter(a).map(async r=>{const i=await C(r.name,t);n[r.name]=i.filter(u=>!(r.builtin&&u.aliases===null)).map(u=>{const g=x(u),$=u.aliases?.find(F=>F.name==="lts");return{...g,isLts:$!==void 0,registryBuiltIn:r.builtin,registryName:r.name,server:r.config?.url,title:g.os+g.release_title+g.release+g.server}}).sort(E)})),c=[];o.forEach(r=>{r.status!=="fulfilled"&&c.push(r.reason)});const p=(r,i,u)=>i===u.findIndex(g=>g.title===r.title),m=r=>{delete r.type,r.versions={vm:{items:{"disk1.img":{ftype:"disk1.img"}}}}},l=["ubuntu","ubuntu-minimal","ubuntu-daily","ubuntu-minimal-daily"];l.forEach(r=>{const i=r in n?n[r]:[];n[r]=i.filter(p),n[r].map(m),n[r].reverse().sort(R)});const y=[...n.ubuntu,...n["ubuntu-minimal"],..."images"in n?n.images:[],...n["ubuntu-daily"],...n["ubuntu-minimal-daily"]];return Object.entries(n).forEach(([r,i])=>{!l.includes(r)&&r!=="images"&&y.push(...i)}),{images:y,error:c.join(". ")}},se=(t,e)=>{const{isFineGrained:s}=S();return f({queryKey:[b.images,t],queryFn:async()=>J(t,s),enabled:(e??!0)&&s!==null})},te=t=>{const{isFineGrained:e}=S();return f({queryKey:[b.images],queryFn:async()=>K(e),enabled:e!==null})},ae=()=>{const{isFineGrained:t}=S(),{hasImageRegistries:e}=A(),{project:s}=v(),a=f({queryKey:[b.images,"selector",e],queryFn:async()=>H(),enabled:!e}),n=f({queryKey:[b.images,"selector",e,s?.name],queryFn:async()=>X(!!t,s),enabled:e&&t!==null&&s!==null});return e?n:a};export{se as a,W as b,D as c,k as d,ee as e,Y as f,Z as g,te as h,G as i,_ as m,ae as u};