PageSourceSearch

https://sxlighting.com/assets/admin.blog.index-C9PheOE4.js

js sxlighting.com collected 2026-10-06 12:31:10 UTC 16,291 bytes, 1 lines download raw bytes

1import{a as P,bf as I,b as E,w as xe,v as pe,r as l,j as e,L as he,s as V,t as n}from"./index-CApWdvTX.js";import{u as R}from"./useServerFn-Bvsv00h_.js";import{a as fe}from"./restyle.functions-k5-7j_bW.js";const be=P({method:"POST"}).middleware([I]).handler(E("6023626a36162af0dd7208c6ea566e752eac199639e8a3a9ab805fd9700cd7a4")),ye=P({method:"POST"}).middleware([I]).handler(E("87b9958e5aef9d5331eaa574a97a676cdc4893f0651626bc663351b52e77ee93")),je=P({method:"POST"}).middleware([I]).handler(E("36c34647bbecb2d8163ee0b72888b157f61b52e97288a3f1d320148eb7006a1f"));function we(){const G=xe(),{session:u}=pe(),H=R(be),J=R(ye),T=R(je),K=R(fe),[i,Q]=l.useState([]),[X,L]=l.useState(!0),[C,F]=l.useState(""),[$,M]=l.useState("all"),[a,h]=l.useState({open:!1,items:[],index:0,processing:!1}),p=l.useRef([]),[Y,Z]=l.useState(!1),[B,ee]=l.useState("https://sxlighting.com/blog"),[m,te]=l.useState([]),[f,j]=l.useState({done:0,total:0,current:""}),[v,N]=l.useState(!1),[O,se]=l.useState(!0),b=a.items.length,z=a.items.filter(t=>["done","failed","skipped"].includes(t.restyleStatus)).length,g=a.items[a.index],re=b>0&&z===b,k=async()=>{L(!0);const{data:t,error:r}=await V.from("blog_posts").select("id, slug, title, status, published_at, updated_at, restyled_at, category:blog_categories(slug, name)").order("updated_at",{ascending:!1});r?n.error(r.message):Q(t??[]),L(!1)};l.useEffect(()=>{k()},[]);const ae=async t=>{if(!confirm("Excluir este artigo?"))return;const{error:r}=await V.from("blog_posts").delete().eq("id",t);if(r){n.error(r.message);return}n.success("Artigo excluído"),k()},oe=async t=>{if(!u?.access_token){n.error("Sessão expirada. Entre novamente.");return}const r=n.loading("Reimportando imagens...");try{const s=await T({data:{id:t},headers:{Authorization:`Bearer ${u.access_token}`}});n.success(`${s.rehosted} imagens salvas${s.failed?`, ${s.failed} falharam`:""}${s.coverUpdated?" · capa atualizada":""}`,{id:r}),k()}catch(s){n.error(s.message,{id:r})}},ne=async()=>{if(!u?.access_token||!confirm(`Reimportar imagens de TODOS os ${i.length} artigos? Pode demorar.`))return;N(!0),j({done:0,total:i.length,current:""});let t=0,r=0;for(let s=0;s<i.length;s++){const c=i[s];j({done:s,total:i.length,current:c.title});try{await T({data:{id:c.id},headers:{Authorization:`Bearer ${u.access_token}`}}),t++}catch(d){console.error("rehost falhou",c.slug,d),r++}}j({done:i.length,total:i.length,current:""}),N(!1),n.success(`${t} processados, ${r} falharam`),k()},w=(t,r)=>{p.current=p.current.map(s=>s.id===t?{...s,...r}:s),h(s=>({...s,items:p.current}))},[D,U]=l.useState(!1),q=async(t=!1)=>{if(!u?.access_token){n.error("Sessão expirada. Entre novamente.");return}const r=t?i.filter(c=>!c.restyled_at):i;if(r.length===0){n.info(t?"Nenhum artigo pendente — todos já foram reestilizados.":"Nenhum artigo encontrado.");return}const s=r.map(c=>({...c,restyleStatus:"pending"}));p.current=s,h({open:!0,items:s,index:0,processing:!1}),U(!0)},[A,ie]=l.useState(!0),_=async t=>{if(!u?.access_token){n.error("Sessão expirada. Entre novamente.");return}const r=t??a.index,s=p.current[r];if(!s)return;N(!0),h(o=>({...o,processing:!0,index:r})),w(s.id,{restyleStatus:"processing",restyleMessage:void 0});const c=3;let d=null,x=!1;for(let o=1;o<=c;o++)try{await K({data:{id:s.id},headers:{Authorization:`Bearer ${u.access_token}`}}),w(s.id,{restyleStatus:"done",restyleMessage:o>1?`Reestilizado (tentativa ${o})`:"Reestilizado e salvo"}),n.success(`Reestilizado: ${s.title}`),x=!0;break}catch(S){d=S;const y=d.message||"",me=/rate limit|429|timeout|network|fetch failed|503|502|504/i.test(y);if(console.warn(`restyle tentativa ${o}/${c} falhou`,s.slug,y),o<c&&me){w(s.id,{restyleStatus:"processing",restyleMessage:`Tentativa ${o} falhou (${y.slice(0,60)}). Tentando novamente...`}),await new Promise(ge=>setTimeout(ge,2e3*o));continue}break}if(x)await k();else{const o=d?.message||"Erro ao reestilizar";console.error("restyle falhou definitivamente",s.slug,d),w(s.id,{restyleStatus:"failed",restyleMessage:o}),n.error(`Falhou: ${s.title} — ${o}`)}if(N(!1),h(o=>({...o,processing:!1})),A&&r+1<p.current.length){const o=r+1;h(S=>({...S,index:o})),setTimeout(()=>_(o),800)}else if(A&&r+1>=p.current.length){const o=p.current.filter(y=>y.restyleStatus==="failed").length,S=p.current.filter(y=>y.restyleStatus==="done").length;n.success(`Fila concluída: ${S} reestilizados, ${o} falharam.`)}};l.useEffect(()=>{D&&a.open&&!a.processing&&a.items.length>0&&(U(!1),_(0))},[D,a.open,a.items.length]);const W=()=>{h(t=>({...t,index:Math.min(t.index+1,Math.max(t.items.length-1,0))}
1))},le=()=>{const t=a.items[a.index];t&&(w(t.id,{restyleStatus:"skipped",restyleMessage:"Pulado manualmente"}),W())},ce=async()=>{if(!u?.access_token){n.error("Sessão expirada. Entre novamente para importar artigos.");return}try{const t=await H({data:{sourceUrl:B,limit:300},headers:{Authorization:`Bearer ${u.access_token}`}});te(t.urls),n.success(`${t.count} artigos encontrados`)}catch(t){n.error(t.message)}},de=t=>{try{return new URL(t).pathname.replace(/\/+$/,"").split("/").pop()??""}catch{return""}},ue=async()=>{if(m.length===0)return;if(!u?.access_token){n.error("Sessão expirada. Entre novamente para importar artigos.");return}let t=m,r=0;if(O){const d=new Set(i.map(x=>x.slug));if(t=m.filter(x=>!d.has(de(x))),r=m.length-t.length,t.length===0){n.info(`Todos os ${m.length} já existem. Nada para importar.`);return}n.info(`${r} já existem · importando ${t.length} novos`)}N(!0),j({done:0,total:t.length,current:""});let s=0,c=0;for(let d=0;d<t.length;d++){const x=t[d];j({done:d,total:t.length,current:x});try{await J({data:{url:x,downloadImages:!0},headers:{Authorization:`Bearer ${u.access_token}`}}),s++}catch(o){console.error("Falha em",x,o),c++}}j({done:t.length,total:t.length,current:""}),N(!1),n.success(`${s} importados, ${c} falharam${r?`, ${r} pulados`:""}`),k()};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-display text-xl text-foreground",children:"Artigos do blog"}),e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:[i.length," artigos · ✨ ",i.filter(t=>t.restyled_at).length," reestilizados por IA · ",i.filter(t=>!t.restyled_at).length," pendentes"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsx("button",{onClick:ne,disabled:v||i.length===0,className:"border border-border px-4 py-2 text-xs uppercase tracking-[0.2em] text-foreground hover:bg-surface disabled:opacity-50",title:"Baixa todas as imagens dos posts e re-hospeda no nosso storage",children:"Reimportar imagens (todos)"}),e.jsx("button",{onClick:()=>q(!0),disabled:v||i.length===0,className:"border border-accent bg-accent/10 px-4 py-2 text-xs uppercase tracking-[0.2em] text-accent-foreground hover:bg-accent disabled:opacity-50",title:"Reestiliza apenas os artigos que ainda não passaram pela IA",children:"✨ Reestilizar pendentes"}),e.jsx("button",{onClick:()=>q(!1),disabled:v||i.length===0,className:"border border-border px-4 py-2 text-xs uppercase tracking-[0.2em] text-foreground hover:bg-surface disabled:opacity-50",title:"Reestiliza TODOS os artigos (mesmo os já reestilizados)",children:"✨ Reestilizar todos"}),e.jsx("button",{onClick:()=>Z(t=>!t),className:"border border-border px-4 py-2 text-xs uppercase tracking-[0.2em] text-foreground hover:bg-surface",children:"Importar do WordPress"}),e.jsx("button",{onClick:()=>G({to:"/admin/blog/$id",params:{id:"novo"}}),className:"bg-foreground px-4 py-2 text-xs uppercase tracking-[0.2em] text-background hover:bg-foreground
1/90",children:"+ Novo artigo"})]})]}),Y&&e.jsxs("div",{className:"border border-hairline bg-surface p-6",children:[e.jsx("h3",{className:"font-display text-base text-foreground",children:"Importador WordPress"}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"Faz crawl da listagem do blog e importa todos os posts encontrados (título, conteúdo, imagem de capa, autor e data)."}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-3",children:[e.jsx("input",{type:"url",value:B,onChange:t=>ee(t.target.value),className:"min-w-[320px] flex-1 border border-border bg-background px-3 py-2 text-sm text-foreground",placeholder:"https://sxlighting.com/blog"}),e.jsx("button",{onClick:ce,disabled:v,className:"border border-border px-4 py-2 text-xs uppercase tracking-[0.2em] text-foreground hover:bg-background disabled:opacity-50",children:"1. Descobrir URLs"}),e.jsxs("button",{onClick:ue,disabled:v||m.length===0,className:"bg-foreground px-4 py-2 text-xs uppercase tracking-[0.2em] text-background hover:bg-foreground
1/90 disabled:opacity-50",children:["2. Importar ",m.length>0&&`(${m.length})`]})]}),e.jsxs("label",{className:"mt-3 flex cursor-pointer items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("input",{type:"checkbox",checked:O,onChange:t=>se(t.target.checked),className:"h-3.5 w-3.5 accent-foreground"}),"Pular artigos que já existem (não sobrescrever)"]}),f.total>0&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsxs("span",{children:[f.done," / ",f.total]}),e.jsx("span",{className:"truncate",children:f.current})]}),e.jsx("div",{className:"mt-2 h-1 w-full bg-background",children:e.jsx("div",{className:"h-full bg-foreground transition-all",style:{width:`${f.done/f.total*100}%`}})})]}),m.length>0&&!v&&f.done===0&&e.jsxs("details",{className:"mt-4",children:[e.jsxs("summary",{className:"cursor-pointer text-xs uppercase tracking-wider text-muted-foreground",children:["Ver URLs (",m.length,")"]}),e.jsx("ul",{className:"mt-3 max-h-60 space-y-1 overflow-auto text-xs text-muted-foreground",children:m.map(t=>e.jsx("li",{className:"truncate",children:t},t))})]})]}),a.open&&e.jsxs("div",{className:"border border-accent bg-accent/5 p-6",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-display text-base text-foreground",children:"Reestilização por artigo"}),e.jsxs("p",{className:"mt-2 text-xs text-muted-foreground",children:[z," / ",b," concluídos",g?` · atual: ${g.title}`:""]})]}),e.jsx("button",{onClick:()=>h({open:!1,items:[],index:0,processing:!1}),disabled:a.processing,className:"text-xs uppercase tracking-[0.2em] text-muted-foreground hover:text-foreground disabled:opacity-50",children:"Fechar"})]}),e.jsxs("label",{className:"mt-3 flex cursor-pointer items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("input",{type:"checkbox",checked:A,onChange:t=>ie(t.target.checked),className:"h-3.5 w-3.5 accent-foreground"}),"Modo automático (avança e processa o próximo sozinho)"]}),e.jsx("div",{className:"mt-4 h-1.5 w-full bg-background",children:e.jsx("div",{className:"h-full bg-accent transition-all",style:{width:`${b?z/b*100:0}%`}})}),g&&e.jsx("div",{className:"mt-5 border border-hairline bg-background p-4",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-[10px] uppercase tracking-[0.2em] text-muted-foreground",children:["Artigo ",a.index+1," de ",b," ·"," ",g.restyleStatus]}),e.jsx("p",{className:"mt-1 truncate font-medium text-foreground",children:g.title}),e.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:["/blog/",g.slug]}),g.restyleMessage&&e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:g.restyleMessage})]}),e.jsxs("div",{className:"flex flex-wrap gap-3 text-xs",children:[e.jsx("button",{onClick:()=>_(),disabled:a.processing||g.restyleStatus==="done",className:"bg-foreground px-4 py-2 uppercase tracking-[0.2em] text-background hover:bg-foreground
1/90 disabled:opacity-50",children:a.processing?"Reestilizando...":"Reestilizar este"}),e.jsx("button",{onClick:le,disabled:a.processing||g.restyleStatus==="done",className:"border border-border px-4 py-2 uppercase tracking-[0.2em] text-foreground hover:bg-surface disabled:opacity-50",children:"Pular"}),e.jsx("button",{onClick:W,disabled:a.processing||a.index>=b-1,className:"border border-accent px-4 py-2 uppercase tracking-[0.2em] text-accent-foreground hover:bg-accent disabled:opacity-50",children:"Próximo"})]})]})}),e.jsx("ul",{className:"mt-4 max-h-64 divide-y divide-hairline overflow-auto border border-hairline bg-background text-xs",children:a.items.map((t,r)=>e.jsxs("li",{className:"flex items-center justify-between gap-3 p-3",children:[e.jsxs("button",{onClick:()=>h(s=>({...s,index:r})),disabled:a.processing,className:"min-w-0 flex-1 truncate text-left text-foreground hover:underline disabled:cursor-default disabled:no-underline",children:[r+1,". ",t.title]}),e.jsx("span",{className:"shrink-0 uppercase tracking-[0.2em] text-muted-foreground",children:t.restyleStatus})]},t.id))}),re&&e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:"Fila concluída. Revise os artigos e feche esta tela quando terminar."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 border border-hairline bg-surface p-3",children:[e.jsx("input",{type:"search",value:C,onChange:t=>F(t.target.value),placeholder:"Buscar por título, slug ou categoria...",className:"min-w-[280px] flex-1 border border-border bg-background px-3 py-2 text-sm text-foreground"}),e.jsxs("select",{value:$,onChange:t=>M(t.target.value),className:"border border-border bg-background px-3 py-2 text-xs uppercase tracking-[0.2em] text-foreground",children:[e.jsx("option",{value:"all",children:"Todos status"}),e.jsx("option",{value:"published",children:"Publicados"}),e.jsx("option",{value:"draft",children:"Rascunhos"})]}),(C||$!=="all")&&e.jsx("button",{onClick:()=>{F(""),M("all")},className:"text-xs uppercase tracking-[0.2em] text-muted-foreground hover:text-foreground",children:"Limpar"})]}),(()=>{const t=C.trim().toLowerCase(),r=i.filter(s=>$!=="all"&&s.status!==$?!1:t?s.title.toLowerCase().includes(t)||s.slug.toLowerCase().includes(t)||(s.category?.name.toLowerCase().includes(t)??!1):!0);return X?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Carregando..."}):r.length===0?e.jsx("p",{className:"py-12 text-center text-sm text-muted-foreground",children:i.length===0?"Nenhum artigo. Crie um ou importe do WordPress.":"Nenhum artigo corresponde à busca."}):e.jsx("ul",{className:"divide-y divide-hairline border border-hairline",children:r.map(s=>e.jsxs("li",{className:"flex items-center justify-between gap-4 p-4 hover:bg-surface",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:`text-[10px] uppercase tracking-[0.2em] ${s.status==="published"?"text-foreground":"text-muted-foreground"}`,children:s.status==="published"?"Publicado":"Rascunho"}),s.category&&e.jsxs("span",{className:"text-[10px] uppercase tracking-[0.2em] text-muted-foreground",children:["· ",s.category.name]}),s.restyled_at?e.jsx("span",{className:"rounded-sm border border-accent bg-accent/10 px-1.5 py-0.5 text-[10px] uppercase tracking-[0.2em] text-accent-foreground",title:`Reestilizado por IA em ${new Date(s.restyled_at).toLocaleString("pt-BR")}`,children:"✨ IA"}):e.jsx("span",{className:"rounded-sm border border-hairline px-1.5 py-0.5 text-[10px] uppercase tracking-[0.2em] text-muted-foreground",title:"Ainda não foi reestilizado por IA",children:"pendente IA"})]}),e.jsx("p",{className:"mt-1 truncate font-medium text-foreground",children:s.title}),e.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:["/blog/",s.slug]})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsx("button",{onClick:()=>oe(s.id),className:"uppercase tracking-[0.2em] text-muted-foreground hover:text-foreground hover:underline",title:"Re-hospedar imagens deste post",children:"Imagens"}),e.jsx(he,{to:"/admin/blog/$id",params:{id:s.id},className:"uppercase tracking-[0.2em] text-foreground hover:underline",children:"Editar"}),e.jsx("button",{onClick:()=>ae(s.id),className:"uppercase tracking-[0.2em] text-destructive hover:underline",children:"Excluir"})]})]},s.id))})})()]})}
1export{we as component};

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.