PageSourceSearch

https://americaspoliticalpulse.com/assets/PressUrlsAdmin-BAxMTc7-.js

js americaspoliticalpulse.com collected 2026-09-28 08:30:54 UTC 19,470 bytes, 1 lines download raw bytes

1import{r,j as e}from"./vendor-chartjs-DAQApR3A.js";import{u as _e}from"./AdminToastContext-CgqwTXQu.js";import{g as S,h as C}from"./adminAuth-CHjczaih.js";import"./index-VXtZNIH-.js";import"./vendor-recharts-KyLwo51t.js";import"./vendor-maps-DjSiDsVE.js";const P="https://ttpch1cg2k.execute-api.us-east-1.amazonaws.com",z={officials:{label:"Officials",noun:"official",idField:"bioguide_id",listKey:"officials",basePath:"/officials/press-urls",description:"Review and update press release page URLs for federal officials",searchHint:"name, state, or bioguide ID"},governors:{label:"Governors",noun:"governor",idField:"governor_id",listKey:"governors",basePath:"/governors/press-urls",description:"Review and update press release page URLs for sitting governors",searchHint:"name, state, or governor ID"}},G={found:{bg:"#10b98120",text:"#10b981"},needs_review:{bg:"#f59e0b20",text:"#f59e0b"},not_found:{bg:"#ef444420",text:"#ef4444"},error:{bg:"#ef444420",text:"#ef4444"},unknown:{bg:"#6b728020",text:"#6b7280"}};function X(c){return c.last_run_error?"error":c.press_release_url_status||"unknown"}function Le(){const[c,oe]=r.useState("officials"),n=z[c],[u,L]=r.useState([]),[ie,D]=r.useState(!0),[m,b]=r.useState("needs_review"),[h,K]=r.useState(""),[ce,J]=r.useState(null),[v,E]=r.useState(""),[F,T]=r.useState("found"),[R,g]=r.useState(""),[i,U]=r.useState("auto"),[d,j]=r.useState(""),[f,_]=r.useState(""),[V,Y]=r.useState(!1),[y,q]=r.useState(0),[$,de]=r.useState([]),[x,xe]=r.useState(0),[pe,ue]=r.useState(!1),[p,Q]=r.useState(!1),[Z,ee]=r.useState(!1),[me,H]=r.useState(!1),[te,O]=r.useState(null),[he,se]=r.useState(!1),[I,re]=r.useState("selector"),[A,M]=r.useState("container"),ae=r.useRef(null),{showError:N,showSuccess:k}=_e(),fe=async()=>{D(!0);try{const t=await fetch(`${P}${n.basePath}`,{headers:{"x-admin-password":S()}});if(t.status===401)return C();if(!t.ok)throw new Error(`HTTP ${t.status}`);const s=await t.json(),a=s[n.listKey]||[];L(a.map(l=>({...l,id:l[n.idField]}))),q(s.scrape_failed||0)}catch(t){N(`Failed to load ${n.label.toLowerCase()}`,t)}finally{D(!1)}},ye=async()=>{try{const t=await fetch(`${P}${n.basePath}/scrape-failures`,{headers:{"x-admin-password":S()}});if(t.status===401)return C();if(!t.ok)throw new Error(`HTTP ${t.status}`);const s=await t.json(),a=s.failures||[];de(a.map(l=>({...l,id:l[n.idField]??null}))),xe(s.total||0),ue(!!s.truncated)}catch(t){N("Failed to load scrape failures",t)}},le=()=>{fe(),ye()};r.useEffect(()=>{le()},[c]),r.useEffect(()=>{function t(s){const a=ae.current;if(!a||s.source!==a.contentWindow)return;const l=s.data;l?.type==="prl-xpath"&&(I==="selector"?typeof l.xpath=="string"&&l.xpath&&(g(l.xpath),w(),k("Selector captured — review and save")):A==="container"?typeof l.xpath=="string"&&l.xpath&&(j(l.xpath),M("example")):(_(l.href||""),w(),k("Release area + example captured — review and save")))}return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[I,A,k]);const be=t=>{t!==c&&(B(),Q(!1),ee(!1),K(""),b("needs_review"),L([]),oe(t))},W=r.useMemo(()=>u.filter(t=>{const s=p||m==="all"||X(t)===m,a=!h||`${t.first_name} ${t.last_name}`.toLowerCase().includes(h.toLowerCase())||(t.state||"").toLowerCase().includes(h.toLowerCase())||(t.id||"").toLowerCase().includes(h.toLowerCase()),l=!p||!!t.last_run_error;return s&&a&&l}),[u,m,h,p]),ve=r.useMemo(()=>{const t={};for(const s of u){const a=X(s);t[a]=(t[a]||0)+1}return t},[u]),ge=t=>{J(t.id),E(t.scrape_press_release_url||t.press_release_url||""),T(t.press_release_url_status||"found"),g(t.next_page_selector||""),U(t.pagination_type||"auto"),j(t.list_container_xpath||""),_(t.example_link_url||"")},B=()=>{J(null),E(""),T("found"),g(""),U("auto"),j(""),_("")},je=async t=>{Y(!0);try{const s=await fetch(`${P}${n.basePath}/update`,{method:"POST",headers:{"x-admin-password":S(),"Content-Type":"application/json"},body:JSON.stringify({[n.idField]:t,press_release_url:v||null,press_release_url_status:F,next_page_selector:R||null,pagination_type:i,list_container_xpath:d||null,example_link_url:f||null})});if(s.status===401)return C();if(!s.ok)throw new Error(`HTTP ${s.status}`);const a=u.find(l=>l.id===t);L(l=>l.map(o=>o.id===t?{...o,press_release_url:v||null,scrape_press_release_url:v||null,next_page_selector:R||null,pagination_type:i,list_container_xpath:d||null,example_link_url:f||null,press_release_url_status:F,last_run_error:null,last_run_error_text:null}:o)),a?.last_run_error&&q(l=>Math.max(0,l-1)),B(),k("Saved — will be retried on the next scrape run")}catch(s){N("Failed to update",s)}finally{Y(!1)}},ne=async(t,s="selector")=>{re(s),M("container"),H(!0),O(null),se(!0);try{const a=await fetch(`${P}/press-urls/proxy?entity=${c}&id=${encodeURIComponent(t)}`,{headers:{"x-admin-password":S()}});if(a.status===401)return C();if(!a.ok){const l=await a.json().catch(()=>({detail:`HTTP ${a.status}`}));throw new Error(l.detail||`HTTP ${a.status}`)}O(await a.text())}catch(a){N("Could not load the page for picking",a),H(!1)}finally{se(!1)}},w=()=>{H(!1),O(null),re("selector"),M("container")};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",style:{color:"var(--text-primary)"},children:"Press Release URLs"}),e.jsx("p",{className:"text-sm mt-1",style:{color:"var(--text-secondary)"},children:n.description})]}),e.jsxs("button",{onClick:le,className:"px-4 py-2 rounded-lg text-sm font-medium",style:{background:"var(--bg-tertiary)",color:"var(--text-secondary)",border:"1px solid var(--border)"},children:[e.jsx("i",{className:"bi bi-arrow-clockwise mr-2"}),"Refresh"]})]}),e.jsx("div",{className:"flex gap-2 mb-6",children:Object.keys(z).map(t=>{const s=c===t;return e.jsx("button",{onClick:()=>be(t),className:"px-4 py-2 rounded-lg text-sm font-medium",style:{background:s?"var(--accent)":"var(--bg-secondary)",color:s?"#fff":"var(--text-secondary)",border:`1px solid ${s?"var(--accent)":"var(--border)"}`},children:z[t].label},t)})}),ie?e.jsxs("div",{className:"animate-pulse",children:[e.jsx("div",{className:"h-8 w-64 roun
1ded mb-4",style:{background:"var(--bg-secondary)"}}),e.jsx("div",{className:"h-64 rounded",style:{background:"var(--bg-secondary)"}})]}):e.jsxs(e.Fragment,{children:[(y>0||x>0)&&e.jsxs("div",{className:"rounded-lg p-4 mb-6",style:{background:"#ef444415",border:"1px solid #ef444455"},children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{className:"text-sm",style:{color:"var(--text-primary)"},children:[e.jsx("i",{className:"bi bi-exclamation-triangle-fill mr-2",style:{color:"#ef4444"}}),e.jsx("span",{className:"font-semibold",children:"Last ingest run had failures."})," ",y>0&&e.jsxs("span",{children:[y," ",n.noun,y===1?"":"s"," failed URL discovery"]}),y>0&&x>0&&" · ",x>0&&e.jsxs("span",{children:[x," URL",x===1?"":"s"," failed to scrape"]})]}),e.jsxs("div",{className:"flex gap-2",children:[y>0&&e.jsx("button",{onClick:()=>{const t=!p;Q(t),t&&b("all")},className:"px-3 py-1.5 rounded text-xs font-medium",style:{background:p?"#ef4444":"var(--bg-tertiary)",color:p?"#fff":"var(--text-secondary)",border:"1px solid var(--border)"},children:p?`Show all ${n.label.toLowerCase()}`:`Show failed ${n.label.toLowerCase()}`}),x>0&&e.jsx("button",{onClick:()=>ee(t=>!t),className:"px-3 py-1.5 rounded text-xs font-medium",style:{background:"var(--bg-tertiary)",color:"var(--text-secondary)",border:"1px solid var(--border)"},children:Z?"Hide failed URLs":"View failed URLs"})]})]}),Z&&$.length>0&&e.jsxs("div",{className:"mt-4 rounded-lg overflow-hidden",style:{background:"var(--bg-secondary)",border:"1px solid var(--border)"},children:[e.jsx("div",{style:{maxHeight:360,overflowY:"auto"},children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{style:{borderBottom:"1px solid var(--border)"},children:[e.jsx("th",{className:"text-left px-3 py-2 text-xs font-medium",style:{color:"var(--text-secondary)"},children:n.label.replace(/s$/,"")}),e.jsx("th",{className:"text-left px-3 py-2 text-xs font-medium",style:{color:"var(--text-secondary)"},children:"URL"}),e.jsx("th",{className:"text-left px-3 py-2 text-xs font-medium",style:{color:"var(--text-secondary)"},children:"Error"}),e.jsx("th",{className:"text-right px-3 py-2 text-xs font-medium",style:{color:"var(--text-secondary)"},children:"Tries"})]})}),e.jsx("tbody",{children:$.map(t=>e.jsxs("tr",{style:{borderBottom:"1px solid var(--border)"},children:[e.jsxs("td",{className:"px-3 py-2 text-xs whitespace-nowrap",style:{color:"var(--text-primary)"},children:[t.first_name||t.last_name?`${t.first_name||""} ${t.last_name||""}`.trim():t.id||"--",(t.party||t.state)&&e.jsxs("span",{style:{color:"var(--text-muted)"},children:[" (",t.party,"-",t.state,")"]})]}),e.jsx("td",{className:"px-3 py-2 text-xs",children:e.jsxs("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"underline break-all",style:{color:"var(--accent)"},children:[t.url.replace(/^https?:\/\//,"").slice(0,60),t.url.replace(/^https?:\/\//,"").length>60?"...":""]})}),e.jsx("td",{className:"px-3 py-2 text-xs",style:{color:"#ef4444",maxWidth:320},title:t.scrape_error||"",children:(t.scrape_error||"unknown").slice(0,120)}),e.jsx("td",{className:"px-3 py-2 text-xs text-right",style:{color:"var(--text-muted)"},children:t.scrape_attempts??0})]},t.url))})]})}),pe&&e.jsxs("div",{className:"px-3 py-2 text-xs",style:{color:"var(--text-muted)"},children:["Showing first ",$.length," of ",x," failed URLs."]})]})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 mb-6",children:["found","needs_review","not_found","error"].map(t=>{const s=G[t],a=m===t;return e.jsxs("button",{onClick:()=>b(m===t?"all":t),className:"p-3 rounded-lg text-left transition-all",style:{background:a?s.bg:"var(--bg-secondary)",border:`1px solid ${a?s.text:"var(--border)"}`},children:[e.jsx("div",{className:"text-2xl font-bold",style:{color:s.text},children:ve[t]||0}),e.jsx("div",{className:"text-xs mt-1 capitalize",style:{color:"var(--text-secondary)"},children:t.replace("_"," ")})]},t)})}),e.jsx("div",{className:"mb-4",children:e.jsx("input",{type:"text",value:h,onChange:t=>K(t.target.value),placeholder:`Search by ${n.searchHint}...`,className:"w-full px-4 py-2 rounded-lg",style:{background:"var(--bg-secondary)",border:"1px solid var(--border)",color:"var(--text-primary)"}})}),e.jsxs("div",{className:"text-sm mb-3",style:{color:"var(--text-muted)"},children:["Showing ",W.length," of ",u.length," ",n.label.toLowerCase(),m!=="all"&&e.jsx("button",{onClick:()=>b("all"),className:"ml-2 underline",style:{color:"var(--accent)"},children:"show all"})]}),e.jsxs("div",{className:"rounded-xl overflow-hidden",style:{background:"var(--bg-secondary)",border:"1px solid var(--border)"},children:[e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{style:{borderBottom:"1px solid var(--border)"},children:[e.jsx("th",{className:"text-left px-4 py-3 text-sm font-medium",style:{color:"var(--text-secondary)"},children:n.label.replace(/s$/,"")}),e.jsx("th",{className:"text-left px-4 py-3 text-sm font-medium",style:{color:"var(--text-secondary)"},children:"Status"}),e.jsx("th",{className:"text-left px-4 py-3 text-sm font-medium hidden lg:table-cell",style:{color:"var(--text-secondary)"},children:"Gov Website"}),e.jsx("th",{className:"text-left px-4 py-3 text-sm font-medium",style:{color:"var(--text-secondary)"},children:"Press URL"}),e.jsx("th",{className:"text-right px-4 py-3 text-sm font-medium",style:{color:"var(--text-secondary)"},children:"Actions"})]})}),e.jsx("tbody",{children:W.map(t=>{const s=ce===t.id,a=X(t),l=G[a]||G.unknown;return e.jsxs("tr",{style:{borderBottom:"1px solid var(--border)"},children:[e.jsxs("td",{className:"px-4 py-3",children:[e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--text-primary)"},children:[t.first_name," ",t.last_name]}),e.jsxs("div",{className:"text-xs",style:{color:"var(--text-muted)"},children:[t.party," - ",t.state]}),t.last_run_error?e.jsxs("div",{className:"text-xs mt-1 break-words",style:{color:"#ef4444",maxWidth:280},title:t.last_run_error_text||"",children:[e.jsx("i",{className:"bi bi-exclamation-triangle mr-1"}),t.last_run_error_text||"Scrape failed last run"]}):null]}),e.jsx("td",{className:"px-4 py-3",children:s?e.jsxs("select",{value:F,onChange:o=>T(o.target.value),className:"px-2 py-1 rounded text-xs",style:{background:"var(--bg-tertiary)",border:"1px solid var(--border)",color:"var(--text-primary)"},children:[e.jsx("option",{value:"found",children:"Found"}),e.jsx("option",{value:"needs_review",children:"Needs Review"}),e.jsx("option",{value:"not_found",children:"Not Found"}),e.jsx("option",{value:"error",children:"Error"})]}):e.jsx("span",{className:"px-2 py-0.5 rounded text-xs font-medium capitalize",style:{background:l.bg,color:l.text},children:a.replace("_"," ")})}),e.jsx("td",{className:"px-4 py-3 hidden lg:table-cell",children:t.government_website?e.jsx("a",{href:t.government_website,target:"_blank",rel:"noopener noreferrer",className:"text-xs underline",style:{color:"var(--accent)"},children:new URL(t.government_website).hostname}):e.jsx("span",{className:"text-xs",style:{color:"var(--text-muted)"},children:"--"})}),e.jsx("td",{className:"px-4 py-3",children:s?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("input",{type:"url",value:v,onCh
1ange:o=>E(o.target.value),placeholder:"https://… press-release listing page",title:"The page the scraper crawls for press-release links",className:"w-full px-2 py-1 rounded text-xs",style:{background:"var(--bg-tertiary)",border:"1px solid var(--border)",color:"var(--text-primary)",minWidth:200}}),e.jsxs("select",{value:i,onChange:o=>U(o.target.value),title:"How the scraper should page through this listing",className:"w-full px-2 py-1 rounded text-xs",style:{background:"var(--bg-tertiary)",border:"1px solid var(--border)",color:"var(--text-primary)",minWidth:200},children:[e.jsx("option",{value:"auto",children:"Pagination: Auto-detect"}),e.jsx("option",{value:"none",children:"Pagination: None (page 1 only)"}),e.jsx("option",{value:"click",children:"Pagination: Click “Next”"}),e.jsx("option",{value:"scroll",children:"Pagination: Infinite scroll"}),e.jsx("option",{value:"url",children:"Pagination: URL pattern"})]}),(i==="auto"||i==="click"||i==="url")&&e.jsx("input",{type:"text",value:R,onChange:o=>g(o.target.value),placeholder:i==="url"?"URL pattern, e.g. ?page={n}":"next-page selector (optional)",title:i==="url"?"URL pattern for page N — use {n} (e.g. ?page={n}) or a bare suffix (?page=).":"Pagination 'next page' XPath/CSS selector. Leave blank to auto-detect.",className:"w-full px-2 py-1 rounded text-xs",style:{background:"var(--bg-tertiary)",border:"1px solid var(--border)",color:"var(--text-muted)",minWidth:200,fontFamily:"monospace"}}),(i==="click"||i==="auto")&&(t.scrape_press_release_url||t.press_release_url)&&e.jsxs("button",{type:"button",onClick:()=>ne(t.id),className:"text-xs underline inline-flex items-center",style:{color:"var(--accent)"},title:"Open the press page and click the 'next page' element to fill the selector",children:[e.jsx("i",{className:"bi bi-bullseye mr-1"}),"Pick visually"]}),(t.scrape_press_release_url||t.press_release_url)&&e.jsxs("div",{className:"pt-1 mt-1",style:{borderTop:"1px dashed var(--border)"},children:[e.jsxs("button",{type:"button",onClick:()=>ne(t.id,"hint"),className:"text-xs underline inline-flex items-center",style:{color:"var(--accent)"},title:"Point GPT at the release list: click the container, then one example link",children:[e.jsx("i",{className:"bi bi-crosshair mr-1"}),"Help GPT find releases"]}),(d||f)&&e.jsxs("div",{className:"text-xs mt-1",style:{color:"var(--text-muted)"},children:[d&&e.jsxs("div",{className:"break-all",title:d,children:["container: ",e.jsxs("code",{children:[d.slice(0,40),d.length>40?"…":""]})]}),f&&e.jsxs("div",{className:"break-all",title:f,children:["example: ",e.jsxs("code",{children:[f.replace(/^https?:\/\//,"").slice(0,40),"…"]})]}),e.jsx("button",{type:"button",onClick:()=>{j(""),_("")},className:"underline",style:{color:"var(--text-muted)"},children:"clear hint"})]})]})]}):t.scrape_press_release_url||t.press_release_url?e.jsxs("a",{href:t.scrape_press_release_url||t.press_release_url,target:"_blank",rel:"noopener noreferrer",className:"text-xs underline break-all",style:{color:"var(--accent)"},children:[(t.scrape_press_release_url||t.press_release_url).replace(/^https?:\/\//,"").slice(0,50),(t.scrape_press_release_url||t.press_release_url).replace(/^https?:\/\//,"").length>50?"...":""]}):e.jsx("span",{className:"text-xs",style:{color:"var(--text-muted)"},children:"--"})}),e.jsx("td",{className:"px-4 py-3 text-right whitespace-nowrap",children:s?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>je(t.id),disabled:V,className:"p-1 mr-1",style:{color:"#10b981",opacity:V?.5:1},title:"Save",children:e.jsx("i",{className:"bi bi-check-lg"})}),e.jsx("button",{onClick:B,className:"p-1",style:{color:"var(--text-muted)"},title:"Cancel",children:e.jsx("i",{className:"bi bi-x-lg"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>ge(t),className:"p-1 mr-1 hover:opacity-70",style:{color:"var(--text-secondary)"},title:"Edit",children:e.jsx("i",{className:"bi bi-pencil"})}),(t.scrape_press_release_url||t.press_release_url)&&e.jsx("a",{href:t.scrape_press_release_url||t.press_release_url,target:"_blank",rel:"noopener noreferrer",className:"p-1 hover:opacity-70 inline-block",style:{color:"var(--text-secondary)"},title:"Open URL",children:e.jsx("i",{className:"bi bi-box-arrow-up-right"})})]})})]},t.id)})})]}),W.length===0&&e.jsxs("div",{className:"px-4 py-8 text-center",style:{color:"var(--text-muted)"},children:["No ",n.label.toLowerCase()," found"]}
1)]})]}),me&&e.jsx("div",{className:"fixed inset-0 z-50 flex",style:{background:"rgba(0,0,0,0.6)"},onClick:w,children:e.jsxs("div",{className:"m-auto rounded-xl overflow-hidden flex flex-col shadow-2xl",style:{width:"92vw",height:"88vh",background:"var(--bg-secondary)",border:"1px solid var(--border)"},onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2",style:{borderBottom:"1px solid var(--border)"},children:[e.jsxs("div",{className:"text-sm",style:{color:"var(--text-primary)"},children:[e.jsx("i",{className:"bi bi-crosshair mr-2",style:{color:"#ef4444"}}),I==="selector"?e.jsxs(e.Fragment,{children:["Click the ",e.jsx("b",{children:"“next page”"})," element — its XPath fills the selector."]}):A==="container"?e.jsxs(e.Fragment,{children:[e.jsx("b",{children:"Step 1 of 2"})," — click the box that ",e.jsx("b",{children:"contains the list"})," of releases."]}):e.jsxs(e.Fragment,{children:[e.jsx("b",{children:"Step 2 of 2"})," — now click ",e.jsx("b",{children:"one example release link"}),"."]})]}),e.jsx("button",{onClick:w,className:"p-1",style:{color:"var(--text-muted)"},title:"Close",children:e.jsx("i",{className:"bi bi-x-lg"})})]}),e.jsx("div",{className:"flex-1",style:{background:"#fff"},children:he||!te?e.jsx("div",{className:"h-full flex items-center justify-center text-sm",style:{color:"#666"},children:"Loading press page…"}):e.jsx("iframe",{ref:ae,title:"Press page selector picker",sandbox:"allow-scripts",srcDoc:te,style:{width:"100%",height:"100%",border:0}})})]})})]})}export{Le as PressUrlsAdmin};

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.