code wiki / _hdl_build / nx_hub_page.nx
nx_hub_page.nx source
↩ module page · 57 lines · 4437 B
1// nx_hub_page.nx -- the clean LANDING HUB for nishifamily.com (served behind the Nishi Family OPAQUE).
2// One page that fans out to every branch: Wiki, Library, Ops, Games, Media, AI, ... Each branch is a
3// card; live branches link, coming branches are marked honestly. Emitted to wiki_pages/hub.html so the
4// OPAQUE daemon's gated /wiki route already serves it. Sovereign: nx_syscalls + nx_wiki_skin_lib.
5// license_tier: ORIGINAL
6import "nx_syscalls.nx"
7import "nx_wiki_skin_lib.nx"
8const HUB_MAGIC_262144: i64 = 262144
9
10const HUB_OUT: *u8 = "/mnt/c/Users/elder/nishi-core/nxc2/knowledge/wiki_pages/hub.html"
11
12// PER-USER PRIVATE ACCESS: owner-only cards (Gallery, Advertising, ...) are NEVER hardcoded into the
13// hub HTML -- they are fetched at runtime from the server-authorized /access endpoint (no-cookie
14// X-Nishi-Session token). /access returns ONLY the links keyed to this user's handle (or "*"), so a
15// non-owner family member's response contains no owner cards -> they never exist in that user's page.
16// This is the fix for "the gallery card must not exist for other nishifamily users ever" -- the secret
17// lives in the server's entitlements, not in the shared HTML. Public links (/wiki,/video) are skipped
18// here because they already appear as branch cards above.
19const HUB_ACCESS_JS: *u8 = "<script>(function(){var t=sessionStorage.getItem('nsess');if(!t)return;fetch('/access',{headers:{'X-Nishi-Session':t}}).then(function(r){return r.ok?r.json():null}).then(function(j){if(!j||!j.links)return;var pub={'/wiki':1,'/video':1};var out='';for(var i=0;i<j.links.length;i++){var L=j.links[i];if(pub[L.url])continue;out+='<a class=\"card\" href=\"'+L.url+'\"><b>'+L.label+' →</b><span>Private — only visible to you.</span></a>'}if(out){document.getElementById('pa').innerHTML=out;document.getElementById('ph').style.display=''}}).catch(function(){})})();</script>"
20
21func hp_card(buf: *u8, off: i64, href: *u8, title: *u8, desc: *u8, live: i64) -> i64 {
22 var o: i64 = off
23 if live == 1 {
24 o = sk_cat(buf, o, "<a class=\"card\" href=\"" as *u8); o = sk_cat(buf, o, href)
25 o = sk_cat(buf, o, "\"><b>" as *u8); o = sk_cat(buf, o, title)
26 o = sk_cat(buf, o, " →</b><span>" as *u8); o = sk_cat(buf, o, desc); o = sk_cat(buf, o, "</span></a>\n" as *u8)
27 } else {
28 o = sk_cat(buf, o, "<div class=\"card\" style=\"opacity:.62\"><b>" as *u8); o = sk_cat(buf, o, title)
29 o = sk_cat(buf, o, " <span class=\"sub\" style=\"font-weight:400\">· coming</span></b><span>" as *u8); o = sk_cat(buf, o, desc); o = sk_cat(buf, o, "</span></div>\n" as *u8)
30 }
31 return o
32}
33
34func main(argc: i64, argv: *i64) -> i64 {
35 let h: *u8 = sys_mmap(HUB_MAGIC_262144)
36 var w: i64 = 0
37 w = skin_open(h, w, "Hub" as *u8, "home" as *u8)
38 w = sk_cat(h, w, "<h1>Nishi Family</h1>\n<p class=\"sub\">Your private hub — one OPAQUE login, every branch. Signed in with a no-cookie Nishi Family session.</p>\n" as *u8)
39 w = sk_cat(h, w, "<h2>Branches</h2>\n" as *u8)
40 w = hp_card(h, w, "index.html" as *u8, "Wiki" as *u8, "Everything we’ve built — 1,195 cross-linked pages, auto-generated from our work." as *u8, 1)
41 w = hp_card(h, w, "#" as *u8, "Library" as *u8, "Books + the reader, consolidated. ~5,700 titles." as *u8, 0)
42 w = hp_card(h, w, "#" as *u8, "Ops" as *u8, "Live up/down monitoring of nishifamily.com and every branch." as *u8, 0)
43 w = hp_card(h, w, "#" as *u8, "Games" as *u8, "Our games." as *u8, 0)
44 w = hp_card(h, w, "#" as *u8, "Media" as *u8, "SFW media." as *u8, 0)
45 w = hp_card(h, w, "#" as *u8, "AI" as *u8, "The hook for your local LLM + Claude + other aligned AIs working with the Nishi ecosystem." as *u8, 0)
46 // owner-only cards are injected here at runtime from /access (server-authorized; empty for non-owners)
47 w = sk_cat(h, w, "<h2 id=\"ph\" style=\"display:none\">Your private access</h2>\n<div id=\"pa\"></div>\n" as *u8)
48 w = sk_cat(h, w, HUB_ACCESS_JS)
49 w = skin_close(h, w, sys_now_realtime_sec())
50 let fd: i64 = sys_openat_wr(HUB_OUT, 420)
51 if fd < 0 { sys_write(2, "HUB-FAIL\n" as *u8, 9); sys_exit(1); return 1 }
52 sys_write(fd, h, w); sys_close(fd)
53 let r: *u8 = sys_mmap(96); var ro: i64 = 0
54 ro = sk_cat(r, ro, "HUB-PAGE-OK bytes=" as *u8); ro = sk_catn(r, ro, w); ro = sk_cat(r, ro, " -> wiki_pages/hub.html\n" as *u8)
55 sys_write(1, r, ro)
56 sys_exit(0); return 0
57}