import"./rolldown-runtime-DIIn1E2Q.js";import{n as e}from"./types-DPJvCrdo.js";import{r as t,v as n}from"./formatUtil-CeKPWstn.js";import{t as r}from"./electronDownloadStore-DudKQmD7.js";var i=[`https://civitai.com/`,`https://huggingface.co/`,`http://localhost:`],a=[`.safetensors`,`.sft`,`.ckpt`,`.pth`,`.pt`],o=new Set([`https://huggingface.co/stabilityai/stable-zero123/resolve/main/stable_zero123.ckpt`,`https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_depth_sd14v1.pth?download=true`,`https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth`]);function isModelDownloadable(e){return o.has(e.url)?!0:!(!i.some(t=>e.url.startsWith(t))||!a.some(t=>e.name.endsWith(t)))}function downloadModel(t,n){if(!e){let e=document.createElement(`a`);e.href=t.url,e.download=t.name,e.target=`_blank`,e.rel=`noopener noreferrer`,e.click();return}let i=n[t.directory];i?.[0]&&r().start({url:t.url,savePath:i[0],filename:t.name})}var s=new Map,c=new Map;async function fetchCivitaiMetadata(e){try{let t=new URL(e).pathname,n=t.match(/^\/api\/download\/models\/(\d+)$/)??t.match(/^\/api\/v1\/models-versions\/(\d+)$/);if(!n)return{fileSize:null,gatedRepoUrl:null};let[,r]=n,i=`https://civitai.com/api/v1/model-versions/${r}`,a=await fetch(i);if(!a.ok)return{fileSize:null,gatedRepoUrl:null};let o=(await a.json()).files?.find(t=>{let n=t.downloadUrl;return typeof n==`string`&&n.length>0&&n.startsWith(e)});return{fileSize:o?.sizeKB?o.sizeKB*1024:null,gatedRepoUrl:null}}catch{return{fileSize:null,gatedRepoUrl:null}}}var l=new Set([401,403,451]);async function fetchHeadMetadata(e){try{let n=await fetch(e,{method:`HEAD`});if(!n.ok)return e.includes(`huggingface.co`)&&l.has(n.status)?{fileSize:null,gatedRepoUrl:t(e)}:{fileSize:null,gatedRepoUrl:null};let r=n.headers.get(`content-length`),i=r?parseInt(r,10):null;return{fileSize:i!==null&&!Number.isNaN(i)?i:null,gatedRepoUrl:null}}catch{return{fileSize:null,gatedRepoUrl:null}}}function isComplete(e){return e.fileSize!==null||e.gatedRepoUrl!==null}async function fetchModelMetadata(e){let t=s.get(e);if(t!==void 0)return t;let r=c.get(e);if(r)return r;let i=(async()=>{let t=n(e)?await fetchCivitaiMetadata(e):await fetchHeadMetadata(e);return isComplete(t)&&s.set(e,t),t})();c.set(e,i);try{return await i}finally{c.delete(e)}}export{fetchModelMetadata as n,isModelDownloadable as r,downloadModel as t};
//# sourceMappingURL=missingModelDownload-Elln16Ad.js.map