import{b as w,s as d}from"./index-BxIwIJfy.js";import{E as y}from"./vue-core-Di3IuVqe.js";const i=y(new Map),m=720*1e3;let u=new Set,c=null;const p=n=>n&&n.url&&n.expire>Date.now();async function g(){const n=[...u];if(u=new Set,c=null,!!n.length)try{const r=await w.post(`${d.lienApi}/fichier/lien`,{chemins:n}),f=Date.now()+m;for(const s of n){const a=r.data?.[s];i.set(s,{url:a?`${d.lienApi}/${a}`:"",expire:f})}}catch{for(const r of n)i.delete(r)}}function h(n){return u.add(n),c||(c=Promise.resolve().then(g)),c}function A(){const n=e=>{if(!e)return"";const t=i.get(e);return p(t)?t.url:(t||h(e),t?.url||"")},r=async e=>{if(!e)return"";const t=i.get(e);return p(t)?t.url:(await h(e),i.get(e)?.url||"")};return{lien:n,lienAsync:r,ouvrirFichier:async e=>{const t=await r(e);return t&&window.open(t,"_blank","noopener"),t},telechargerFichier:async(e,t)=>{const l=await r(e);if(!l)return"";const o=document.createElement("a");return o.href=`${l}&telecharger=1`,t&&(o.download=t),o.style.display="none",document.body.appendChild(o),o.click(),o.remove(),l},oublierLien:e=>i.delete(e)}}export{A as u};
