code wiki / _hdl_build / nx_source_admin.nx

nx_source_admin.nx source

↩ module page · 60 lines · 4218 B

1// nx_source_admin.nx -- SOURCE/API MANAGER (operator 2026-06-13: "ability to manage all the apis, the 2// systems"). One sovereign admin view over EVERY data source the ecosystem can ingest from: 3// - worldwide scholarly sources (knowledge/registry/worldwide_sources.tsv) 4// - media/ingest sources (knowledge/registry/media_sources.tsv) 5// - credential/data requests (knowledge/registry/cred_requests.tsv) 6// Renders knowledge/source_admin.html: per-source kind/access/status + which need a key (-> cred lane 7// -> nx_password_vault). The operator manages it all here; PROVIDED keys unlock the API lanes. Re-run 8// via renameat (no-trunc). license_tier: ORIGINAL 9import "nx_syscalls.nx" 10const K_MAGIC_65536: i64 = 65536 11const K_MAGIC_65535: i64 = 65535 12 13func sa_w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } 14func sa_rf(path: *u8, buf: *u8, cap: i64) -> i64 { let fd: i64=sys_openat_rd(path); if fd<0{return 0} var tot: i64=0; var r: i64=1; while r>0 { let d: *u8=((buf as i64)+tot) as *u8; r=sys_read(fd,d,cap-tot); if r>0{tot=tot+r} } sys_close(fd); return tot } 15func sa_scan(buf: *u8, n: i64, start: i64, delim: i64) -> i64 { var i: i64=start; var s: i64=1; while s==1 { if i>=n{s=0} else { if buf[i]==(delim as u8){s=0} else {i=i+1} } } return i } 16 17// render a TSV file's data rows (skip '#') as a <table>, escaping <>&, TAB->cell 18func sa_table(fd: i64, buf: *u8, n: i64) -> i64 { 19 var p: i64=0 20 var atstart: i64=1 21 var skip: i64=0 22 var incell: i64=0 23 while p<n { 24 let c: i64 = buf[p] as i64 25 if atstart==1 { 26 atstart=0 27 if c==35 { skip=1 } else { skip=0; sa_w(fd,"<tr><td>" as *u8); incell=1 } 28 } 29 if skip==0 { 30 if c==10 { if incell==1 { sa_w(fd,"</td></tr>\n" as *u8); incell=0 } atstart=1 } 31 else { if c==9 { sa_w(fd,"</td><td>" as *u8) } 32 else { if c==60 { sa_w(fd,"&lt;" as *u8) } 33 else { if c==62 { sa_w(fd,"&gt;" as *u8) } 34 else { if c==38 { sa_w(fd,"&amp;" as *u8) } 35 else { sys_write(fd,(buf as i64+p) as *u8,1) } } } } } 36 } else { if c==10 { atstart=1; skip=0 } } 37 p=p+1 38 } 39 if incell==1 { sa_w(fd,"</td></tr>\n" as *u8) } 40 return 0 41} 42 43func main() -> i64 { 44 let ww: *u8 = sys_mmap(K_MAGIC_65536); let wn: i64 = sa_rf("knowledge/registry/worldwide_sources.tsv" as *u8, ww, K_MAGIC_65535) 45 let md: *u8 = sys_mmap(K_MAGIC_65536); let mn: i64 = sa_rf("knowledge/registry/media_sources.tsv" as *u8, md, K_MAGIC_65535) 46 let cr: *u8 = sys_mmap(K_MAGIC_65536); let crn: i64 = sa_rf("knowledge/registry/cred_requests.tsv" as *u8, cr, K_MAGIC_65535) 47 48 let of: i64 = sys_openat_wr("knowledge/source_admin.html.tmp" as *u8, 0x1a4) 49 if of<0 { return 1 } 50 sa_w(of, "<!doctype html><html><head><meta charset=\"utf-8\"><title>Nishi Source/API Manager</title><style>body{font-family:system-ui;margin:2rem;max-width:70rem}h1{color:#0b2545}h2{color:#13315c;margin-top:1.6rem}table{border-collapse:collapse;width:100%;margin:.4rem 0}td,th{border:1px solid #cdd7e3;padding:6px;text-align:left;font-size:13px}tr:first-child td{background:#eef3f8;font-weight:700}</style></head><body>\n" as *u8) 51 sa_w(of, "<h1>Nishi &mdash; Source / API Manager</h1><p>Every data source the ecosystem can ingest from, in one place. Sources needing a key are flagged in the credential lane (provide via the vault &rarr; the API lane unlocks). Beyond Google Scholar = open + valuable sources from everywhere, ingested into the library.</p>\n" as *u8) 52 sa_w(of, "<h2>Worldwide scholarly sources</h2><table>\n" as *u8); sa_table(of, ww, wn); sa_w(of, "</table>\n" as *u8) 53 sa_w(of, "<h2>Media / ingest sources</h2><table>\n" as *u8); sa_table(of, md, mn); sa_w(of, "</table>\n" as *u8) 54 sa_w(of, "<h2>Credential / data requests (provide keys here)</h2><table>\n" as *u8); sa_table(of, cr, crn); sa_w(of, "</table>\n" as *u8) 55 sa_w(of, "</body></html>\n" as *u8) 56 sys_close(of) 57 sys_renameat("knowledge/source_admin.html.tmp" as *u8, "knowledge/source_admin.html" as *u8) 58 sa_w(1, "SOURCEADMIN rendered knowledge/source_admin.html (worldwide+media+creds) verdict=GREEN\n" as *u8) 59 return 0 60}