1import{s as l}from"./index-CPK_JSUK.js";const f="empresa-logos";function u(e){return typeof e=="string"&&/^data:image\//i.test(e.trim())}function d(e){var p;const t=e.indexOf(","),a=e.slice(0,t),r=e.slice(t+1),o=(((p=/data:([^;]+)/i.exec(a))==null?void 0:p[1])||"image/png").toLowerCase(),n=o.includes("png")?"png":o.includes("jpeg")||o.includes("jpg")?"jpg":o.includes("webp")?"webp":o.includes("gif")?"gif":o.includes("svg")?"svg":"png",i=atob(r),s=new Uint8Array(i.length);for(let c=0;c<i.length;c++)s[c]=i.charCodeAt(c);return{blob:new Blob([s],{type:o}),ext:n}}async function m(e,t,a){if(!a||!u(a))return a??void 0;if(!e||!t)return a;try{const{blob:r,ext:o}=d(a),n=`${e}/${t}.${o}`,{error:i}=await l.storage.from(f).upload(n,r,{upsert:!0,contentType:r.type,cacheControl:"31536000"});if(i)throw i;const{data:s}=l.storage.from(f).getPublicUrl(n);return`${s.publicUrl}?v=${Date.now()}`}catch(r){return console.error("Falha ao subir logo para o Storage; mantendo base64:",r),a}}const g=new Set;async function h(e){if(!(!e||g.has(e))){g.add(e);try{const{data:t,error:a}=await l.from("empresas").select("id, logo").eq("user_id",e).like("logo","data:image/%");if(a||!t||t.length===0)return;for(const r of t){const o=await m(e,r.id,r.logo);if(o&&o!==r.logo){const{error:n}=await l.from("empresas").update({logo:o}).eq("id",r.id).eq("user_id",e);n&&console.error("Falha ao atualizar URL do logo:",n)}}}catch(t){g.delete(e),console.error("Migração de logos para o Storage falhou (best-effort):",t)}}}export{m as ensureLogoInStorage,u as isDataUri,h as migrateBase64LogosToStorage};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.