1import{q as b,v as g,r as c,_ as T,t as n,j as e}from"./index-lnBFix7s.js";import{r as j}from"./auth-middleware-DOfTxIv4.js";const C=b({method:"POST"}).middleware([j]).handler(g("693720ec33a2b6d85770668760512eabc22bdd8ad56e3c01f35005c3c1e02ae3")),I=b({method:"GET"}).middleware([j]).handler(g("cbf0230a03ae707971d59c133d2d02dd615d779e67625cbe2e995c177d1d82e9")),_=b({method:"POST"}).middleware([j]).handler(g("4216e05ed6c8529a44116df11d24f97ac2fa373601b8fa0c8755b8868b565e9d")),O=b({method:"POST"}).middleware([j]).handler(g("3e1cb1b76fda4436483150bf4da9db48f2b96457313d8379c66b360955963b32")),B=b({method:"POST"}).middleware([j]).handler(g("551f9adf38a09510df8f35e8a25c31d2be913638d3c5c634b0e2ffa992f4be42")),E=b({method:"POST"}).middleware([j]).handler(g("e2c3c1020183f65be48c2bd92cee86ddb467968bb988df975c0db14811972372")),P=b({method:"POST"}).middleware([j]).handler(g("ed36a286ea2e5669a9c47f34df0b200ab03235e210f9c91a95264fbcfd354693"));function A(){const[s,o]=c.useState(null),[p,w]=c.useState(!0),[m,S]=c.useState(20),[d,u]=c.useState(!1),y=c.useRef(!1);c.useEffect(()=>{let t=!1;return(async()=>{try{const{supabase:r}=await T(async()=>{const{supabase:h}=await import("./index-lnBFix7s.js").then(k=>k.ae);return{supabase:h}},[]),{data:x}=await r.auth.getSession();if(!x.session||(await new Promise(h=>setTimeout(h,50)),t))return;const f=await _();if(t)return;f.ok&&f.job&&o(f.job)}catch(r){console.error("load latest job failed",r)}})(),()=>{t=!0}},[]),c.useEffect(()=>{if(!s||y.current||s.status!=="pending"&&s.status!=="running")return;y.current=!0;let t=!1;return(async()=>{for(;!t;)try{const r=await E({data:{jobId:s.id}});if(!r.ok){n.error(`Import error: ${r.error}`);break}if(r.job){if(o(r.job),r.job.status==="completed"){n.success("Import complete");break}if(r.job.status==="failed"||r.job.status==="cancelled")break}await new Promise(x=>setTimeout(x,400))}catch(r){n.error(r?.message??"tick failed");break}y.current=!1})(),()=>{t=!0}},[s?.id]);const v=async()=>{u(!0);try{const t=await C({data:{downloadMedia:p,perPage:m}});if(!t.ok){n.error(t.error);return}n.success("Import started");const r=await I({data:{jobId:t.jobId}});r.ok?o(r.job):n.error(r.error)}catch(t){console.error("start import failed",t),n.error(t?.message??"Failed to start import")}finally{u(!1)}},a=async()=>{if(!s)return;await B({data:{jobId:s.id}});const t=await I({data:{jobId:s.id}});t.ok&&o(t.job)},l=async()=>{if(s){u(!0);try{const t=await O({data:{jobId:s.id,perPage:m}});if(!t.ok){n.error(t.error);return}n.success("Resuming import"),o(t.job)}finally{u(!1)}}};return e.jsxs("div",{className:"space-y-6 max-w-3xl",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-serif text-2xl font-bold",children:"Import from Legacy CMS"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Pulls authors, categories, tags, media and posts from the legacy CMS via REST API. Only items missing from the database are inserted â safe to re-run."})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:p,onChange:t=>w(t.target.checked)}),"Download images to Supabase Storage (recommended)"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:["Items per batch:",e.jsx("input",{type:"number",min:5,max:50,value:m,onChange:t=>S(Number(t.target.value)||20),className:"w-20 rounded border px-2 py-1"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:v,disabled:d||s?.status==="running"||s?.status==="pending",className:"rounded bg-primary px-4 py-2 text-sm text-primary-foreground disabled:opacity-50",children:d?"Startingâ¦":"Start import"}),s&&(s.status==="running"||s.status==="pending")&&e.jsx("button",{onClick:a,className:"rounded border px-4 py-2 text-sm hover:bg-muted",children:"Cancel"}),s&&(s.status==="failed"||s.status==="cancelled"||s.status==="running"&&!y.current)&&s.phase!=="done"&&e.jsxs("button",{onClick:l,disabled:d,className:"rounded border px-4 py-2 text-sm hover:bg-muted disabled:opacity-50",children:["Resume ",s.phase," (page ",s.page,")"]})]})]}),s&&e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"text-sm",children:["Status: ",e.jsx("span",{className:"font-semibold",children:s.status})," · Phase:"," ",e.jsx("span",{className:"font-semibold",children:s.phase})," · Page ",s.page]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s.id.slice(0,8)})]}),s.last_message&&e.jsx("div",{className:"text-xs text-muted-foreground",children:s.last_message}),e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"text-left text-xs uppercase tracking-wider text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"py-1",children:"Type"}),e.jsx("th",{children:"Total on WP"}),e.jsx("th",{children:"Inserted"}),e.jsx("th",{children:"Skipped (already had)"})]})}),e.jsx("tbody",{children:["authors","categories","tags","media","posts","pages"].map(t=>e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"py-1.5 capitalize",children:t}),e.jsx("td",{children:s.totals?.[t]??"â"}),e.jsxs("td",{className:"text-emerald-600",children:["+",s.inserted?.[t]??0]}),e.jsx("td",{className:"text-muted-foreground",children:s.skipped?.[t]??0})]},t))})]}),s.errors?.length>0&&e.jsxs("details",{className:"mt-2",children:[e.jsxs("summary",{className:"cursor-pointer text-sm text-destructive",children:[s.errors.length," error",s.errors.length===1?"":"s"]}),e.jsx("ul",{className:"mt-2 max-h-60 overflow-auto rounded border bg-muted/30 p-2 text-xs",children:s.errors.slice(-50).map((t,r)=>e.jsxs("li",{children:[e.jsxs("span",{className:"font-mono",children:["[",t.phase,"]"]})," ",t.message]},r))})]})]}),e.jsx(J,{})]})}function J(){const[s,o]=c.useState(!1),[p,w]=c.useState(100),[m,S]=c.useState(null),[d,u]=c.useState(null),y=async()=>{o(!0);try{const a=await P({data:{limit:p,offset:0}});u(a),n.success(`Backfilled ${a.updated} of ${a.scanned} posts`)}catch(a){n.error(a?.message??"Backfill failed")}finally{o(!1)}},v=async()=>{o(!0),u(null);let a=0,l=0,t=0,r=0,x=0;const f=[],h=[],k={};try{for(;;){const i=await P({data:{limit:p,offset:a}});l++,t+=i.scanned,r+=i.updated,x+=i.skipped;for(const N of i.examples)f.length<10&&f.push(N);for(const N of i.errors??[])h.length<10&&h.push(N);for(const[N,R]of Object.entries(i.skipReasons??{}))k[N]=(k[N]??0)+R;if(S({batches:l,scanned:t,updated:r,skipped:x}),i.updated>0?a=0:a+=p,i.scanned===0||l>=200)break}u({scanned:t,updated:r,skipped:x,examples:f,errors:h,skipReasons:k}),n.success(`Done: ${r} updated across ${l} batches`)}catch(i){n.error(i?.message??"Backfill failed")}finally{o(!1)}};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-semibold",children:"Backfill missing featured images"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:'For posts with no image, fetches the og:image from the legacy site and stores it in seo_meta.og_image. "Run all" loops batches until done.'})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:["Batch size:",e.jsx("input",{type:"number",min:1,max:500,value:p,onChange:a=>w(Number(a.target.value)||100),className:"w-24 rounded border px-2 py-1"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:y,disabled:s,className:"rounded border px-4 py-2 text-sm disabled:opacity-50",children:s?"Runningâ¦":"Run one batch"}),e.jsx("button",{onClick:v,disabled:s,className:"rounded bg-primary px-4 py-2 text-sm text-primary-foreground disabled:opacity-50",children:s?"Runningâ¦":"Run all (loop until done)"})]}),s&&m&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Batch ",m.batches," · Scanned: ",m.scanned," · Updated: ",m.updated," · Skipped: ",m.skipped]}),d&&e.jsxs("div",{className:"text-sm space-y-1",children:[e.jsxs("div",{children:["Total scanned: ",d.scanned," · Updated: ",e.jsx("span",{className:"text-emerald-600",children:d.updated})," · Skipped: ",d.skipped]}),d.skipReasons&&Object.keys(d.skipReasons).length>0&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Skip reasons: ",Object.entries(d.skipReasons).map(([a,l])=>`${a}=${l}
1`).join(", ")]}),d.errors&&d.errors.length>0&&e.jsx("ul",{className:"text-xs text-destructive space-y-0.5",children:d.errors.slice(0,5).map((a,l)=>e.jsxs("li",{children:["#",a.id," ",a.slug,": ",a.error]},l))}),d.examples.length>0&&e.jsx("ul",{className:"text-xs text-muted-foreground space-y-0.5",children:d.examples.map(a=>e.jsxs("li",{children:["#",a.id," ",e.jsx("span",{className:"font-mono",children:a.slug})," â ",a.og_image]},a.id))})]})]})}export{A 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.