PageSourceSearch

https://everything-pr.com/assets/_protected.media-4UlP5nOf.js

js everything-pr.com collected 2026-10-02 03:59:49 UTC 8,808 bytes, 1 lines download raw bytes

1import{r as a,j as e,t as i}from"./index-lnBFix7s.js";import{e as z,f as F,u as I}from"./admin-taxonomy.functions-Cc9RAQid.js";import{u as O}from"./admin-editor.functions-Bo16E-VH.js";import{L as q}from"./loader-circle-VhT7sRLU.js";import{U as W}from"./upload-BW22f5PF.js";import{S as G}from"./search-DNjNBRHw.js";import{I as K}from"./image-DbR8YICp.js";import{X as Q}from"./x-D9fImDg2.js";import{C as V}from"./copy-DuexGQQm.js";import{T as X}from"./trash-2-D6FEVP9_.js";import"./auth-middleware-DOfTxIv4.js";import"./createLucideIcon-oDu_FO0S.js";function Z(l){return new Promise((m,j)=>{const d=new FileReader;d.onload=()=>{const n=String(d.result??""),f=n.indexOf("base64,");m(f>=0?n.slice(f+7):n)},d.onerror=j,d.readAsDataURL(l)})}function H(l){return l?l<1024?`${l} B`:l<1024*1024?`${(l/1024).toFixed(1)} KB`:`${(l/1024/1024).toFixed(2)} MB`:"—"}const U=48;function ce(){const[l,m]=a.useState([]),[j,d]=a.useState(!0),[n,f]=a.useState(0),[o,x]=a.useState(1),[y,A]=a.useState(""),[v,B]=a.useState("all"),[s,u]=a.useState(null),[w,S]=a.useState(!1),[C,k]=a.useState(!1),_=a.useRef(null),[h,D]=a.useState(""),[g,M]=a.useState(""),[b,T]=a.useState(""),$=async()=>{d(!0);try{const t=await z({data:{page:o,pageSize:U,q:y,type:v}});m(t.items),f(t.total)}catch(t){i.error(t?.message??"Failed to load media")}finally{d(!1)}};a.useEffect(()=>{$()},[o,y,v]),a.useEffect(()=>{s&&(D(s.alt_text??""),M(s.caption??""),T(s.title??""))},[s]);const E=async t=>{const r=Array.from(t);if(!r.length)return;S(!0);let p=0;for(const c of r){if(c.size>10*1024*1024){i.error(`${c.name}: max 10MB`);continue}try{const N=await Z(c);await O({data:{filename:c.name,mime_type:c.type||"application/octet-stream",data_base64:N}}),p++}catch(N){i.error(`${c.name}: ${N?.message??"upload failed"}`)}}S(!1),p&&(i.success(`Uploaded ${p}`),x(1),$())},P=async()=>{if(s){k(!0);try{await I({data:{id:s.id,alt_text:h,caption:g,title:b}}),i.success("Saved"),m(t=>t.map(r=>r.id===s.id?{...r,alt_text:h,caption:g,title:b}:r)),u({...s,alt_text:h,caption:g,title:b})}catch(t){i.error(t?.message??"Save failed")}finally{k(!1)}}},R=async t=>{if(window.confirm(`Delete "${t.filename??t.id}"? Posts using it will lose the featured image.`))try{await F({data:{id:t.id}}),i.success("Deleted"),u(null),m(r=>r.filter(p=>p.id!==t.id))}catch(r){i.error(r?.message??"Delete failed")}},L=Math.max(1,Math.ceil(n/U));return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Media library"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{ref:_,type:"file",multiple:!0,accept:"image/*,video/*",className:"hidden",onChange:t=>{t.target.files&&E(t.target.files),t.currentTarget.value=""}}),e.jsxs("button",{onClick:()=>_.current?.click(),disabled:w,className:"inline-flex items-center gap-1 rounded-md bg-primary px-3 py-1.5 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[w?e.jsx(q,{className:"h-4 w-4 animate-spin"}):e.jsx(W,{className:"h-4 w-4"}),"Upload"]})]})]}),e.jsxs("div",{className:"rounded-lg bg-white border p-3 flex flex-wrap items-center gap-2 mb-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[e.jsx(G,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx("input",{type:"search",placeholder:"Search filename, alt, title, caption…",value:y,onChange:t=>{x(1),A(t.target.value)},className:"w-full border rounded pl-8 pr-3 py-1.5 text-sm"})]}),e.jsxs("select",{value:v,onChange:t=>{x(1),B(t.target.value)},className:"border rounded px-2 py-1.5 text-sm",children:[e.jsx("option",{value:"all",children:"All types"}),e.jsx("option",{value:"image",children:"Images"}),e.jsx("option",{value:"video",children:"Videos"}),e.jsx("option",{value:"other",children:"Other"})]}),e.jsxs("span",{className:"text-xs text-muted-foreground ml-auto",children:[n.toLocaleString()," files"]})]}),e.jsx("div",{onDragOver:t=>t.preventDefault(),onDrop:t=>{t.preventDefault(),t.dataTransfer.files.length&&E(t.dataTransfer.files)},className:"rounded-lg bg-white border p-3",children:j?e.jsx("div",{className:"py-12 text-center text-muted-foreground text-sm",children:"Loading…"}):l.length===0?e.jsxs("div",{className:"py-12 text-center text-muted-foreground text-sm",children:[e.jsx(K,{className:"h-8 w-8 mx-auto mb-2 opacity-40"}),"No media yet. Drop files here or click Upload."]}):e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 md:grid-cols-6 lg:grid-cols-8 gap-2",children:l.map(t=>e.jsx("button",{onClick:()=>u(t),className:"group relative aspect-square overflow-hidden rounded border bg-neutral-100 hover:ring-2 hover:ring-primary",title:t.filename??"",children:t.mime_type?.startsWith("image/")?e.jsx("img",{src:t.url,alt:t.alt_text??"",className:"h-full w-full object-cover",loading:"lazy"}):e.jsxs("div",{className:"h-full w-full flex flex-col items-center justify-center text-xs text-muted-foreground p-1 break-all",children:[(t.mime_type??"f
1ile").split("/")[0],e.jsx("span",{className:"opacity-50 mt-1 text-center",children:t.filename?.slice(0,24)})]})},t.id))})}),e.jsxs("div",{className:"flex items-center justify-between mt-3 text-sm text-muted-foreground",children:[e.jsxs("div",{children:["page ",o," of ",L]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{disabled:o<=1,onClick:()=>x(o-1),className:"rounded border bg-white px-3 py-1.5 disabled:opacity-50",children:"Previous"}),e.jsx("button",{disabled:o>=L,onClick:()=>x(o+1),className:"rounded border bg-white px-3 py-1.5 disabled:opacity-50",children:"Next"})]})]}),s&&e.jsx("div",{className:"fixed inset-0 z-50 flex justify-end bg-black/40",onClick:()=>u(null),children:e.jsxs("div",{className:"w-full max-w-md h-full bg-background shadow-xl flex flex-col",onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-4 py-3",children:[e.jsx("div",{className:"font-semibold truncate",children:s.filename??`#${s.id}`}),e.jsx("button",{onClick:()=>u(null),className:"rounded p-1 hover:bg-muted",children:e.jsx(Q,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex-1 overflow-auto p-4 space-y-4",children:[s.mime_type?.startsWith("image/")?e.jsx("img",{src:s.url,alt:s.alt_text??"",className:"w-full rounded border"}):e.jsx("div",{className:"aspect-video rounded border bg-muted flex items-center justify-center text-sm text-muted-foreground",children:s.mime_type}),e.jsxs("dl",{className:"text-xs grid grid-cols-2 gap-x-3 gap-y-1 text-muted-foreground",children:[e.jsx("dt",{children:"Type"}),e.jsx("dd",{className:"text-foreground",children:s.mime_type??"—"}),e.jsx("dt",{children:"Dimensions"}),e.jsx("dd",{className:"text-foreground",children:s.width&&s.height?`${s.width}×${s.height}`:"—"}),e.jsx("dt",{children:"Size"}),e.jsx("dd",{className:"text-foreground",children:H(s.filesize)}),e.jsx("dt",{children:"Uploaded"}),e.jsx("dd",{className:"text-foreground",children:new Date(s.uploaded_at??s.created_at).toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium mb-1",children:"URL"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{readOnly:!0,value:s.url,className:"flex-1 rounded border px-2 py-1 text-xs bg-muted/30"}),e.jsx("button",{onClick:()=>{navigator.clipboard.writeText(s.url),i.success("Copied")},className:"rounded border p-1.5 hover:bg-muted",title:"Copy URL",children:e.jsx(V,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium mb-1",children:"Alt text"}),e.jsx("input",{value:h,onChange:t=>D(t.target.value),className:"w-full rounded border px-3 py-1.5 text-sm",placeholder:"Describe the image for screen readers / SEO"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium mb-1",children:"Title"}),e.jsx("input",{value:b,onChange:t=>T(t.target.value),className:"w-full rounded border px-3 py-1.5 text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium mb-1",children:"Caption"}),e.jsx("textarea",{value:g,onChange:t=>M(t.target.value),rows:3,className:"w-full rounded border px-3 py-1.5 text-sm"})]})]}),e.jsxs("div",{className:"border-t px-4 py-3 flex items-center justify-between",children:[e.jsxs("button",{onClick:()=>R(s),className:"inline-flex items-center gap-1 rounded border border-red-200 px-3 py-1.5 text-sm text-red-700 hover:bg-red-50",children:[e.jsx(X,{className:"h-3.5 w-3.5"})," Delete"]}),e.jsx("button",{onClick:P,disabled:C,className:"rounded bg-primary px-4 py-1.5 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:C?"Saving…":"Save"})]})]})})]})}export{ce 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.