1import{s as d,Q as f,L as w}from"./index-BBjWjbBk.js";const h="pt-BR";function u(t){return String(t||"").trim()||h}async function y(t,i){const o=(t||[]).map(s=>String(s).toLowerCase()).filter(Boolean);if(!o.length)return{};const{data:n,error:a}=await d.from("affiliate_portals").select("network_destination, instagram_handle, slug, language");if(a)return console.warn("[multilang] falha ao carregar idiomas dos afiliados",a.message),{};const e={};for(const s of n||[]){const g=[s.network_destination,s.instagram_handle,s.slug].filter(Boolean).map(r=>String(r).replace(/^@/,"").toLowerCase()),c=o.find(r=>g.includes(r));if(!c)continue;const l=u(s.language);l!==u(i)&&(e[l]||(e[l]=[])).push(c)}return e}async function _(t,i){const n=await(await fetch(t)).blob();return new File([n],i,{type:n.type||"image/jpeg"})}async function p(t,i,o,n){var s;const a=`${o}/assets-v3/${i}/story-${n}-${Date.now()}.jpg`,{error:e}=await w("portal-assets",a,t,{contentType:"image/jpeg",upsert:!0,cacheControl:"31536000"},`story-${n}`);return e?(console.warn("[multilang] upload da arte traduzida falhou",n,e.message),null):((s=d.storage.from("portal-assets").getPublicUrl(a).data)==null?void 0:s.publicUrl)??null}async function S(t){const i=await y(t.destinations,t.sourceLang),o=Object.keys(i);if(!o.length)return{};console.log("[multilang] idiomas de destino",o);const n={};for(const a of o)try{const{data:e,error:s}=await d.functions.invoke("translate-article",{body:{news_ai_id:t.newsAiId,lang:a,source_lang:t.sourceLang}});if(s)throw new Error(s.message);const g=e==null?void 0:e.translation;if(!g)continue;const c=String(g.art_headline||g.title||"");let l=null;if(t.baseImageUrl&&c)try{const r=await f(t.baseImageUrl,c,t.logoUrl,{brand:t.brand});if(r){const m=await _(r,`story-${a}.jpg`);l=await p(m,t.newsAiId,t.portalId,a)}}catch(r){console.warn("[multilang] arte traduzida falhou",a,r)}n[a]={lang:a,art_headline:c,story_image_url:l,generated_at:new Date().toISOString()}}catch(e){console.warn("[multilang] tradução falhou",a,e)}if(Object.keys(n).length)try{const{data:a}=await d.from("news_ai").select("image_meta").eq("id",t.newsAiId).maybeSingle(),e=a!=null&&a.image_meta&&typeof a.image_meta=="object"?a.image_meta:{};await d.from("news_ai").update({image_meta:{...e,translated_assets:{...e.translated_assets||{},...n}}}).eq("id",t.newsAiId)}catch(a){console.warn("[multilang] persistência das artes traduzidas falhou",a)}return n}export{h as DEFAULT_LANG,S as prepareMultilingualAssets,y as resolveDestinationLanguages};
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.