1import{ag as g,ah as b,r as h,b as T,t as p,j as e,L as n}from"./index-CZ63uMbh.js";import{u as L}from"./useMutation-Dav0WHC3.js";import{C as o,a as d,b as l,d as i,e as f,c as v}from"./card-eMmN0GeS.js";import{B as k}from"./button-DV0NliWQ.js";import{D as E}from"./database-CKOoOoqx.js";import{S as j}from"./shield-alert--LuG8ja-.js";import{H as P,F as A}from"./hard-drive-FRz4IS8f.js";import{A as R}from"./archive-BG6mhR4n.js";import"./index-B6kdtPCW.js";import"./index-Gc50gddj.js";const F=g({method:"GET"}).handler(b("260ef608760127b322bf80772e8dee235cd0fa976b869ee2eb85dda50d1b0502")),U=g({method:"GET"}).handler(b("e56dab9928868ccdeca4a2f49a3c4f5dd1bc8e9fefc9f9bb20dd10ea17322eb1")),I=g({method:"POST"}).handler(b("eaca4fab93d6879cc1fa35cc43c3e62779915967584465501b65f22b200c9efa"));function K(){const[a,N]=h.useState(!1),[c,y]=h.useState(!1);h.useEffect(()=>{const s=t=>{if(a||c)return t.preventDefault(),t.returnValue="Processing assets. Are you sure you want to leave?",t.returnValue};return window.addEventListener("beforeunload",s),()=>window.removeEventListener("beforeunload",s)},[a,c]);const{data:r,isLoading:m,error:u,refetch:O}=T({queryKey:["assets_stats"],queryFn:()=>F()}),_=L({mutationFn:()=>I(),onMutate:()=>{N(!0)},onSuccess:s=>{p.success("Assets ZIP generated successfully!");const t=document.createElement("a");t.href=s.url,t.setAttribute("download","downloaded_assets.zip"),document.body.appendChild(t),t.click(),t.remove()},onError:s=>{p.error(s.message||"Failed to generate assets ZIP."),console.error(s)},onSettled:()=>{N(!1)}}),S=async()=>{y(!0);try{const s=await U(),t=JSON.stringify(s,null,2),C=new Blob([t],{type:"application/json"}),w=URL.createObjectURL(C),x=document.createElement("a");x.href=w,x.download="assets_links.json",document.body.appendChild(x),x.click(),x.remove(),URL.revokeObjectURL(w),p.success("Assets mapping exported successfully.")}catch(s){p.error("Failed to export assets mapping."),console.error(s)}finally{y(!1)}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:"Assets Management"}),e.jsx("p",{className:"text-muted-foreground text-sm mt-1",children:"Monitor your tracked media assets and export them for migrations or backups."})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs(o,{children:[e.jsxs(d,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(l,{className:"text-sm font-medium",children:"Total Tracked Assets"}),e.jsx(E,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(i,{children:[m?e.jsx(n,{className:"h-6 w-6 animate-spin text-muted-foreground"}):u?e.jsxs("span",{className:"text-red-500 text-xs flex items-center gap-1",children:[e.jsx(j,{className:"h-3.5 w-3.5"})," Error loading stats"]}):e.jsxs("div",{className:"flex flex-col gap-1 mt-2",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"text-2xl font-bold",children:r?.active||0}),e.jsx("span",{className:"text-sm text-muted-foreground font-medium",children:"Active"})]}),e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"text-lg font-semibold text-muted-foreground",children:r?.total||0}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Total Tracked"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:"Synchronized inside public.assets_tracker"})]})]}),e.jsxs(o,{children:[e.jsxs(d,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(l,{className:"text-sm font-medium",children:"Storage Providers"}),e.jsx(P,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(i,{children:m?e.jsx(n,{className:"h-6 w-6 animate-spin text-muted-foreground"}):u?e.jsxs("span",{className:"text-red-500 text-xs flex items-center gap-1",children:[e.jsx(j,{className:"h-3.5 w-3.5"})," Error loading stats"]}):e.jsxs("div",{className:"space-y-1 mt-1",children:[Object.entries(r?.byProvider||{}).map(([s,t])=>e.jsxs("div",{className:"flex justify-between items-center text-xs",children:[e.jsx("span",{className:"capitalize font-medium text-muted-foreground",children:s}),e.jsx("span",{className:"font-semibold bg-secondary px-1.5 py-0.5 rounded text-secondary-foreground",children:t})]},s)),Object.keys(r?.byProvider||{}).length===0&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"No providers tracked yet"})]})})]}),e.jsxs(o,{children:[e.jsxs(d,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(l,{className:"text-sm font-medium",children:"Active File Types"}),e.jsx(A,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(i,{children:m?e.jsx(n,{className:"h-6 w-6 animate-spin text-muted-foreground"}):u?e.jsxs("span",{className:"text-red-500 text-xs flex items-center gap-1",children:[e.jsx(j,{className:"h-3.5 w-3.5"})," Error loading stats"]}):e.jsxs("div",{className:"space-y-1 mt-1",children:[Object.entries(r?.byType||{}).map(([s,t])=>e.jsxs("div",{className:"flex justify-between items-center text-xs",children:[e.jsx("span",{className:"capitalize font-medium text-muted-foreground",children:s}),e.jsx("span",{className:"font-semibold bg-secondary px-1.5 py-0.5 rounded text-secondary-foreground",children:t})]},s)),Object.keys(r?.byType||{}).length===0&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"No types tracked yet"})]})})]})]}),e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsxs(o,{className:"flex flex-col",children:[e.jsxs(d,{children:[e.jsxs(l,{className:"flex items-center gap-2",children:[e.jsx(A,{className:"h-5 w-5 text-blue-500"})," Export Asset Mappings"]}),e.jsxs(f,{children:["Generate a JSON file of all tracked assets, formatted exactly like ",e.jsx("code",{children:"assets_links.json"}),"."]})]}),e.jsx(i,{className:"flex-1",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"This mapping contains the table, column, original URL, current URL, and local path for each asset in the system. It mirrors the exact structure needed for migrations."})}),e.jsx(v,{className:"border-t pt-4",children:e.jsx(k,{onClick:S,disabled:c||m,className:"w-full",children:c?e.jsxs(e.Fragment,{children:[e.jsx(n,{className:"mr-2 h-4 w-4 animate-spin"})," Exporting Mappings..."]}):"Export assets_links.json"})})]}),e.jsxs(o,{className:"flex flex-col",children:[e.jsxs(d,{children:[e.jsxs(l,{className:"flex items-center gap-2",children:[e.jsx(R,{className:"h-5 w-5 text-emerald-500"})," Package Downloaded Assets"]}),e.jsxs(f,{children:["Zip the contents of the local ",e.jsx("code",{children:"downloaded_assets"})," folder. Useful for backing up files or transferring them between servers."]})]}),e.jsx(i,{className:"flex-1",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["This process executes on the server and generates a ",e.jsx("code",{children:"downloaded_assets.zip"})," package under your server public assets folder. It automatically downloads when ready."]})}),e.jsx(v,{className:"border-t pt-4",children:e.jsx(k,{onClick:()=>_.mutate(),disabled:a||m,className:"w-full",children:a?e.jsxs(e.Fragment,{children:[e.jsx(n,{className:"mr-2 h-4 w-4 animate-spin"})," Compressing Folder..."]}):"Generate & Download ZIP"})})]})]}),e.jsxs(o,{children:[e.jsxs(d,{children:[e.jsxs(l,{className:"flex items-center gap-2",children:[e.jsx(E,{className:"h-5 w-5 text-indigo-500"})," Assets Migration Guide"]}),e.jsx(f,{children:"Step-by-step instructions to migrate all application files from one host to another."})]}),e.jsxs(i,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-semibold text-sm",children:"Step 1: Export Manifest & Assets ZIP"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Click the action buttons above to download the ",e.jsx("code",{children:"assets_links.json"})," manifest and compile the ",e.jsx("code",{children:"downloaded_assets.zip"})," file package."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-semibold text-sm",children:"Step 2: Unpack Files & Place Manifest"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Extract the files from ",e.jsx("code",{children:"downloaded_assets.zip"})," into the project root directory (forming a ",e.jsx("code",{children:"downloaded_assets/"})," folder). Place the ",e.jsx("code",{children:"assets_links.json"})," file in the project root as well."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"font-semibold text-sm",children:["Step 3: Setup Target Credentials in ",e.jsx("code",{children:".env"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Update the environment variables for your destination workspace. For Supabase, configure ",e.jsx("code",{children:"VITE_SUPABASE_URL"})," and ",e.jsx("code",{children:"SUPABASE_SERVICE_ROLE_KEY"}),". For Cloudinary, set ",e.jsx("code",{children:"VITE_CLOUDINARY_CLOUD_NAME"}),", ",e.jsx("code",{children:"CLOUDINARY_API_KEY"}),", and ",e.jsx("code",{children:"CLOUDINARY_API_SECRET"}),"."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-semibold text-sm",children:"Step 4: Run the Migration Command"}),e.jsxs("p",{className:"text-xs text-muted-foreground mb-2",children:["Execute the migration runner script ",e.jsx("a",{href:"/run_migration.js",download:"run_migration.js",className:"text-blue-500 hover:underline font-mono font-bold bg-blue-50 dark:bg-blue-950/20 px-1.5 py-0.5 rounded",children:"src/run_migration.js (Click to Download)"}),". This script uploads files to your chosen target, rewrites database URLs, and updates tracking states automatically."]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] uppercase font-bold text-muted-foreground block mb-1",children:"1. Test migration with dry-run (simulates uploads):"}),e.jsx("pre",{className:"p-2 bg-muted rounded font-mono text-[10px] overflow-x-auto border",children:"node src/run_migration.js --target supabase --dry-run --limit 5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] uppercase font-bold text-muted-foreground block mb-1",children:"2. Run live migration to Supabase Storage:"}),e.jsx("pre",{className:"p-2 bg-muted rounded font-mono text-[10px] overflow-x-auto border",children:"node src/run_migration.js --target supabase"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] uppercase font-bold text-muted-foreground block mb-1",children:"3. Run live migration to Cloudinary:"}),e.jsx("pre",{className:"p-2 bg-muted rounded font-mono text-[10px] overflow-x-auto border",children:"node src/run_migration.js --target cloudinary"})]})]})]})]})]}),(a||c)&&e.jsx("div",{className:"fixed inset-0 bg-background/80 backdrop-blur-sm z-[9999] flex flex-col items-center justify-center cursor-not-allowed select-none animate-in fade-in duration-300",children:e.jsxs("div",{className:"flex flex-col items-center gap-4 p-6 rounded-xl border bg-card shadow-2xl max-w-md text-center",children:[e.jsx(n,{className:"h-12 w-12 animate-spin text-primary"}),e.jsx("h2",{className:"text-xl font-bold tracking-tight",children:"Processing Assets"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a?"We are fetching all assets from the database and creating the zip archive. This might take a few moments depending on the number of assets. Please do not close or reload this page.":"Exporting assets metadata. Please wait..."}),e.jsx("div",{className:"w-full bg-secondary h-1.5 rounded-full overflow-hidden mt-2",children:e.jsx("div",{className:"bg-primary h-full w-2/3 animate-pulse rounded-full"})})]})})]})}export{K 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.