PageSourceSearch

https://roots-officiel.com/assets/AdminArticleCoversPage-CWsqN-Bj.js

js roots-officiel.com collected 2026-10-09 05:06:56 UTC 18,898 bytes, 1 lines download raw bytes

1import{at as De,ah as Ee,bt as Ze,r as i,b2 as ge,j as e,q as Z,Z as fe,k as T,bo as ve,a3 as Je,B as y,J as be,o as K,bf as je,a2 as ye,d7 as Oe,as as Pe,D as Ne,s as N}from"./index-BTrKqWIn.js";import{J as ze}from"./jszip.min-BNLPlYP-.js";import{L as we}from"./Layout-DWnUI2Xw.js";import"./TabBar-CeFlKNWM.js";const Be=["article-covers","archive-images","editorial-images","landing-images"],J=40,Ge=["analyse","culture","fact-checking","histoire-disrael","histoire-juive","interviews","jewish-world","tsarfatim"],ke=Array.from({length:15},(I,O)=>String(2026-O)),Ce=[["01","Jan"],["02","Fév"],["03","Mar"],["04","Avr"],["05","Mai"],["06","Juin"],["07","Juil"],["08","Août"],["09","Sept"],["10","Oct"],["11","Nov"],["12","Déc"]],W=I=>!!I&&/roots-officiel\.com\/wp-content/i.test(I);function Xe(){var ue,me;const{user:I,isAdmin:O,isLoading:Se}=De(),{toast:p}=Ee(),A=Ze(),[f,X]=i.useState("broken"),[q,Ie]=i.useState(""),[v,H]=i.useState(""),[w,V]=i.useState(""),[k,ee]=i.useState(""),[b,x]=i.useState(0),[u,P]=i.useState(null),[z,Ae]=i.useState(""),[j,te]=i.useState(""),[$,se]=i.useState(""),[_,$e]=i.useState("article-covers"),[B,ae]=i.useState(""),[re,ie]=i.useState(!1),[C,_e]=i.useState("desktop"),[r,S]=i.useState(null),[ne,le]=i.useState(""),[oe,Ue]=i.useState("editorial"),[U,ce]=i.useState(!1),h=ge({queryKey:["admin-covers-articles",f,q,v,w,k,b],queryFn:async()=>{let t=N.from("articles").select("id, title, slug, image_url, mobile_cover_url, category, published_at",{count:"exact"}).order("published_at",{ascending:!1,nullsFirst:!1}).range(b*J,b*J+J-1);f==="broken"&&(t=t.ilike("image_url","%roots-officiel.com/wp-content%"));const s=q.trim();if(s&&(t=t.ilike("title",`%${s}%`)),k&&(t=t.eq("category",k)),v){const n=parseInt(v,10);if(w){const d=parseInt(w,10),l=new Date(Date.UTC(n,d-1,1)).toISOString(),Q=new Date(Date.UTC(d===12?n+1:n,d===12?0:d,1)).toISOString();t=t.gte("published_at",l).lt("published_at",Q)}else{const d=new Date(Date.UTC(n,0,1)).toISOString(),l=new Date(Date.UTC(n+1,0,1)).toISOString();t=t.gte("published_at",d).lt("published_at",l)}}const{data:a,error:o,count:c}=await t;if(o)throw o;return{rows:a||[],total:c||0}}}),G=ge({queryKey:["admin-covers-library",_],queryFn:async()=>{const t=[],s=async(a="")=>{const{data:o,error:c}=await N.storage.from(_).list(a,{limit:1e3,sortBy:{column:"created_at",order:"desc"}});if(c)throw c;for(const n of o||[])if(n.id===null)await s(a?`${a}/${n.name}`:n.name);else if(/\.(jpe?g|png|webp|gif|avif)$/i.test(n.name)){const d=a?`${a}/${n.name}`:n.name,{data:l}=N.storage.from(_).getPublicUrl(d);t.push({bucket:_,name:d,url:l.publicUrl})}};return await s(),t}}),M=i.useMemo(()=>{const t=z.trim().toLowerCase();let s=G.data||[];if(j){const a=$?`${j}/${$}/`:`${j}/`;s=s.filter(o=>o.name.startsWith(a))}return t&&(s=s.filter(a=>a.name.toLowerCase().includes(t))),s},[G.data,z,j,$]),m=i.useMemo(()=>{var t;return((t=h.data)==null?void 0:t.rows.find(s=>s.id===u))||null},[h.data,u]);if(i.useEffect(()=>{var t;!u&&((t=h.data)!=null&&t.rows.length)&&P(h.data.rows[0].id)},[h.data,u]),Se)return e.jsx(we,{children:e.jsx("div",{className:"p-20 flex justify-center",children:e.jsx(Z,{className:"animate-spin"})})});if(!I)return e.jsx(fe,{to:"/gest-r00ts-7x?redirect=/admin/article-covers",replace:!0});if(!O)return e.jsx(fe,{to:"/",replace:!0});const L=async t=>{var o;if(!u){p({title:"Sélectionne un article d'abord",variant:"destructive"});return}const s=C==="desktop"?"image_url":"mobile_cover_url",{error:a}=await N.from("articles").update({[s]:t}).eq("id",u);if(a){p({title:"Erreur",description:a.message,variant:"destructive"});return}if(p({title:C==="desktop"?"Cover desktop assignée ✓":"Cover mobile assignée ✓"}),A.setQueryData(["admin-covers-articles",f,q,v,w,k,b],c=>c&&{...c,rows:c.rows.map(n=>n.id===u?{...n,[s]:t}:n)}),f==="broken"&&C==="desktop"){const c=((o=h.data)==null?void 0:o.rows)||[],n=c.findIndex(l=>l.id===u),d=c.slice(n+1).find(l=>W(l.image_url));d&&P(d.id)}},Fe=async t=>{ie(!0);try{const s=t.name.split(".").pop()||"jpg",a=`manual/${Date.now()}-${Math.random().toString(36).slice(2,8)}.${s}`,{error:o}=await N.storage.from("article-covers").upload(a,t,{contentType:t.type,upsert:!1});if(o)throw o;const{data:c}=N.storage.from("article-covers").getPublicUrl(a);
1await L(c.publicUrl),A.invalidateQueries({queryKey:["admin-covers-library","article-covers"]})}catch(s){p({title:"Upload échoué",description:s.message,variant:"destructive"})}finally{ie(!1)}},Te=async()=>{const t=ne.trim()||(m==null?void 0:m.title)||"";if(!t){p({title:"Décris l'image ou sélectionne un article",variant:"destructive"});return}ce(!0);try{const{data:s,error:a}=await N.functions.invoke("generate-cover-image",{body:{prompt:t,style:oe,aspect:C==="mobile"?"9:16":"16:9"}});if(a)throw a;if(!(s!=null&&s.imageUrl))throw new Error("Pas d'image retournée");await L(s.imageUrl),A.invalidateQueries({queryKey:["admin-covers-library","article-covers"]}),p({title:"Image IA générée et assignée ✓"}),le("")}catch(s){p({title:"Génération échouée",description:(s==null?void 0:s.message)||"Erreur",variant:"destructive"})}finally{ce(!1)}},qe=async t=>{S({total:0,done:0,failed:0,updated:0,current:"Lecture du ZIP…",running:!0,cancel:!1});try{const s=await ze.loadAsync(t),a=[];s.forEach((g,Y)=>{if(Y.dir||!/\.(webp|jpe?g|png|gif|avif)$/i.test(g))return;const D=g.split("/").filter(Boolean);a.push({path:D.join("/"),entry:Y})}),S(g=>g&&{...g,total:a.length,current:`${a.length} images détectées…`});const o="https://eptqkkfulwbkswjinqaz.supabase.co/functions/v1/import-ftp-image",c="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImVwdHFra2Z1bHdia3N3amlucWF6Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjUwOTY4MTYsImV4cCI6MjA4MDY3MjgxNn0.iiyJWdwHhEZGGW2OlIk540ypc5LZ1Bk4mrGXh1DppWg",n=6;let d=0;const l={done:0,failed:0,updated:0},Q=async()=>{for(;;){const g=d++;if(g>=a.length||(r==null?void 0:r.cancel))return;const{path:D,entry:Me}=a[g];try{const F=await Me.async("uint8array");let pe="";const xe=32768;for(let E=0;E<F.length;E+=xe)pe+=String.fromCharCode.apply(null,Array.from(F.subarray(E,E+xe)));const Le=btoa(pe),he=await(await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",apikey:c,Authorization:`Bearer ${c}`},body:JSON.stringify({rel_path:D,base64:Le})})).json();he.uploaded?(l.done++,l.updated+=he.updated||0):l.failed++}catch{l.failed++}S(F=>F&&{...F,done:l.done,failed:l.failed,updated:l.updated,current:D})}};await Promise.all(Array.from({length:n},Q)),p({title:"Import ZIP terminé ✓",description:`${l.done} image(s) uploadée(s), ${l.updated} article(s) mis à jour, ${l.failed} échec(s)`}),A.invalidateQueries({queryKey:["admin-covers-library"]}
1),A.invalidateQueries({queryKey:["admin-covers-articles"]})}catch(s){p({title:"ZIP invalide",description:s.message,variant:"destructive"})}finally{S(s=>s&&{...s,running:!1}),setTimeout(()=>S(s=>s&&!s.running?null:s),4e3)}},R=((ue=h.data)==null?void 0:ue.total)||0,de=Math.max(0,Math.ceil(R/J)-1);return e.jsx(we,{children:e.jsxs("div",{className:"container px-4 py-6 pb-24",children:[e.jsxs("div",{className:"mb-6 flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-2xl font-bold",children:"Bibliothèque & assignation des covers"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:f==="broken"?`${R} article(s) avec cover cassée`:`${R} article(s) au total`})]}),e.jsxs("label",{className:T("inline-flex items-center gap-2 px-4 py-2 rounded-lg bg-primary text-primary-foreground text-sm font-medium cursor-pointer hover:opacity-90 transition shadow",(r==null?void 0:r.running)&&"opacity-50 pointer-events-none"),children:[e.jsx(ve,{className:"h-4 w-4"}),r!=null&&r.running?"Import en cours…":"Importer un ZIP FTP",e.jsx("input",{type:"file",accept:".zip,application/zip,application/x-zip-compressed",className:"hidden",onChange:t=>{var a;const s=(a=t.target.files)==null?void 0:a[0];s&&qe(s),t.target.value=""}})]})]}),r&&e.jsxs("div",{className:"mb-6 border rounded-lg bg-card p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(ve,{className:"h-4 w-4"}),"Import ZIP ",r.running?"en cours":"terminé"]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsxs("span",{className:"text-emerald-600",children:[r.done," ✓"]}),e.jsxs("span",{className:"text-blue-600",children:[r.updated," liés"]}),r.failed>0&&e.jsxs("span",{className:"text-destructive",children:[r.failed," ✗"]}),e.jsxs("span",{className:"text-muted-foreground",children:["/ ",r.total]}),!r.running&&e.jsx("button",{onClick:()=>S(null),className:"text-muted-foreground hover:text-foreground",children:e.jsx(Je,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"h-2 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${r.total?Math.round((r.done+r.failed)*100/r.total):0}%`}})}),e.jsx("div",{className:"text-[11px] text-muted-foreground truncate",children:r.current})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[420px_1fr] gap-6 min-h-[70vh]",children:[e.jsxs("aside",{className:"border rounded-lg bg-card flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"p-3 border-b space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{size:"sm",variant:f==="broken"?"default":"outline",onClick:()=>{X("broken"),x(0)},children:"Cassées"}),e.jsx(y,{size:"sm",variant:f==="all"?"default":"outline",onClick:()=>{X("all"),x(0)},children:"Toutes"})]}),e.jsxs("div",{className:"relative",children:[e.jsx(be,{className:"h-4 w-4 absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"}),e.jsx(K,{placeholder:"Recherche par titre…",value:q,onChange:t=>{Ie(t.target.value),x(0)},className:"pl-9"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-1.5",children:[e.jsxs("select",{value:v,onChange:t=>{H(t.target.value),x(0)},className:"text-xs h-8 px-2 rounded border bg-background",children:[e.jsx("option",{value:"",children:"Année"}),ke.map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsxs("select",{value:w,onChange:t=>{V(t.target.value),x(0)},disabled:!v,className:"text-xs h-8 px-2 rounded border bg-background disabled:opacity-50",children:[e.jsx("option",{value:"",children:"Mois"}),Ce.map(([t,s])=>e.jsx("option",{value:t,children:s},t))]}),e.jsxs("select",{value:k,onChange:t=>{ee(t.target.value),x(0)},className:"text-xs h-8 px-2 rounded border bg-background",children:[e.jsx("option",{value:"",children:"Catégorie"}),Ge.map(t=>e.jsx("option",{value:t,children:t},t))]})]}),(v||w||k)&&e.jsx("button",{onClick:()=>{H(""),V(""),ee(""),x(0)},className:"text-[11px] text-primary hover:underline",children:"Réinitialiser les filtres"})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:h.isLoading?e.jsx("div",{className:"p-8 flex justify-center",children:e.jsx(Z,{className:"animate-spin"})}):e.jsx("ul",{className:"divide-y",children:(me=h.data)==null?void 0:me.rows.map(t=>{const s=W(t.image_url),a=t.id===u;return e.jsx("li",{children:e.jsxs("button",{onClick:()=>P(t.id),className:T("w-full text-left p-3 flex gap-3 items-start hover:bg-muted/50 transition",a&&"bg-primary/10 ring-1 ring-primary"),children:[e.jsx("div",{className:"w-16 h-16 shrink-0 bg-muted rounded overflow-hidden flex items-center justify-center relative",children:t.image_url&&!s?e.jsx("img",{src:t.image_url,alt:"",className:"w-full h-full object-cover",onError:o=>{o.currentTarget.style.display="none"}}):e.jsx(je,{className:"h-5 w-5 text-destructive"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-medium line-clamp-2",children:t.title}),e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground mt-1",children:t.category}),s&&e.jsx("div",{className:"text-[10px] text-destructive mt-1",children:"Cover cassée"})]})]})},t.id)})})}),e.jsxs("div",{className:"p-2 border-t flex items-center justify-between text-xs",children:[e.jsx(y,{size:"sm",variant:"ghost",disabled:b===0,onClick:()=>x(t=>t-1),children:"← Précédent"}
1),e.jsxs("span",{children:[b+1," / ",de+1]}),e.jsx(y,{size:"sm",variant:"ghost",disabled:b>=de,onClick:()=>x(t=>t+1),children:"Suivant →"})]})]}),e.jsxs("section",{className:"border rounded-lg bg-card flex flex-col overflow-hidden",children:[e.jsx("div",{className:"p-4 border-b bg-muted/30",children:m?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Article sélectionné"}),e.jsx("div",{className:"font-semibold truncate",children:m.title}),e.jsx("a",{href:`/article/${m.slug}`,target:"_blank",rel:"noreferrer",className:"text-xs text-primary hover:underline",children:"Voir l'article ↗"})]})}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:["desktop","mobile"].map(t=>{const s=t==="desktop"?m.image_url:m.mobile_cover_url,a=C===t,o=t==="desktop"&&W(s);return e.jsxs("button",{onClick:()=>_e(t),className:T("border rounded-lg overflow-hidden text-left transition",a?"ring-2 ring-primary border-primary":"border-border hover:border-muted-foreground/40 opacity-70"),children:[e.jsx("div",{className:T("bg-muted flex items-center justify-center relative",t==="desktop"?"aspect-video":"aspect-[9/16] max-h-32 mx-auto"),children:s&&!o?e.jsx("img",{src:s,alt:"",className:"w-full h-full object-cover"}):e.jsx(je,{className:"h-6 w-6 text-destructive"})}),e.jsxs("div",{className:"px-2 py-1.5 text-xs flex items-center justify-between",children:[e.jsx("span",{className:"font-medium",children:t==="desktop"?"Desktop (1280×720)":"Mobile (9:16)"}),a&&e.jsx(ye,{className:"h-3.5 w-3.5 text-primary"})]})]},t)})}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Clique sur un emplacement ci-dessus pour choisir où la prochaine image sera assignée."})]}):e.jsx("div",{className:"text-sm text-muted-foreground",children:"Sélectionne un article à gauche"})}),e.jsxs("div",{className:"p-4 border-b space-y-3",children:[e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx(Oe,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(K,{placeholder:"Coller une URL d'image…",value:B,onChange:t=>ae(t.target.value)}),e.jsx(y,{size:"sm",disabled:!B.trim()||!u,onClick:()=>{L(B.trim()),ae("")},children:"Assigner"})]}),e.jsxs("label",{className:T("flex items-center gap-2 px-3 py-2 border-2 border-dashed rounded cursor-pointer hover:bg-muted/50 transition text-sm",re&&"opacity-50 pointer-events-none"),children:[e.jsx(Pe,{className:"h-4 w-4"}),re?"Upload en cours…":"Uploader une nouvelle image (assignée immédiatement)",e.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:t=>{var a;const s=(a=t.target.files)==null?void 0:a[0];s&&Fe(s),t.target.value=""}})]}),e.jsxs("div",{className:"border rounded-lg p-3 space-y-2 bg-gradient-to-br from-primary/5 to-transparent",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(Ne,{className:"h-4 w-4 text-primary"}),"Générer une image avec l'IA"]}),e.jsx("textarea",{value:ne,onChange:t=>le(t.target.value),placeholder:m?`Laisse vide pour utiliser : « ${m.title.slice(0,60)}${m.title.length>60?"…":""} »`:"Décris l'image souhaitée…",rows:2,className:"w-full text-sm px-3 py-2 rounded border bg-background resize-none",disabled:U}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsxs("select",{value:oe,onChange:t=>Ue(t.target.value),disabled:U,className:"text-xs h-8 px-2 rounded border bg-background flex-1",children:[e.jsx("option",{value:"editorial",children:"Éditorial"}),e.jsx("option",{value:"realistic",children:"Photo réaliste"}),e.jsx("option",{value:"illustration",children:"Illustration"}),e.jsx("option",{value:"minimalist",children:"Minimaliste"}),e.jsx("option",{value:"dramatic",children:"Cinématique"})]}),e.jsxs(y,{size:"sm",onClick:Te,disabled:U||!u,className:"gap-1.5",children:[U?e.jsx(Z,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ne,{className:"h-3.5 w-3.5"}),U?"Génération…":"Générer"]})]}),e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:["Format : ",C==="mobile"?"9:16 (mobile)":"16:9 (desktop)"," — assignée auto à l'article sélectionné."]})]})]}),e.jsxs("div",{className:"p-4 border-b space-y-3",children:[e.jsx("div",{className:"flex gap-2 flex-wrap",children:Be.map(t=>e.jsx(y,{size:"sm",variant:_===t?"default":"outline",onClick:()=>$e(t),children:t},t))}),e.jsxs("div",{className:"relative",children:[e.jsx(be,{className:"h-4 w-4 absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"}),e.jsx(K,{placeholder:"Rechercher dans la bibliothèque…",value:z,onChange:t=>Ae(t.target.value),className:"pl-9"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-1.5",children:[e.jsxs("select",{value:j,onChange:t=>te(t.target.value),className:"text-xs h-8 px-2 rounded border bg-background",children:[e.jsx("option",{value:"",children:"Toutes les années"}),ke.map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsxs("select",{value:$,onChange:t=>se(t.target.value),disabled:!j,className:"text-xs h-8 px-2 rounded border bg-background disabled:opacity-50",children:[e.jsx("option",{value:"",children:"Tous les mois"}),Ce.map(([t,s])=>e.jsx("option",{value:t,children:s},t))]})]}),(j||$)&&e.jsx("button",{onClick:()=>{te(""),se("")},className:"text-[11px] text-primary hover:underline",children:"Réinitialiser"}),e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[M.length," image",M.length>
11?"s":""]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:G.isLoading?e.jsx("div",{className:"p-8 flex justify-center",children:e.jsx(Z,{className:"animate-spin"})}):M.length===0?e.jsx("div",{className:"text-center text-muted-foreground py-12 text-sm",children:"Aucune image dans ce bucket."}):e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-3",children:M.map(t=>e.jsxs("button",{onClick:()=>L(t.url),disabled:!u,className:"group relative aspect-square bg-muted rounded overflow-hidden hover:ring-2 hover:ring-primary transition disabled:opacity-50 disabled:cursor-not-allowed",title:t.name,children:[e.jsx("img",{src:t.url,alt:t.name,loading:"lazy",className:"w-full h-full object-cover"}),e.jsx("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/40 transition flex items-center justify-center",children:e.jsx(ye,{className:"h-8 w-8 text-white opacity-0 group-hover:opacity-100 transition"})}),e.jsx("div",{className:"absolute bottom-0 inset-x-0 bg-black/60 text-white text-[10px] px-1 py-0.5 truncate",children:t.name.split("/").pop()})]},`${t.bucket}/${t.name}`))})})]})]})]})})}export{Xe as default};

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.