code wiki / _hdl_build / nx_sitegen_studio.nx

nx_sitegen_studio.nx source

↩ module page · 51 lines · 2539 B

1// nx_sitegen_studio.nx -- the sovereign WYSIWYG STUDIO library (no main; the daemon + the gate import it). 2// se_build_site = the /build endpoint logic: take a posted (UNTRUSTED) .site blueprint, parse + build it 3// through the GOVERNED sovereign engine (nx_sitegen_parse + nx_sitegen, which escape every field and refuse 4// non-UX-compliant pages), and return the built HTML in a buffer. This is what the editor's thin JS POSTs to 5// for its live preview -- the build is ALWAYS the sovereign organ, never JS. se_editor_html = serve the 6// editor client (web_assets/_studio/editor.html). license_tier: ORIGINAL 7import "nx_sitegen_parse.nx" 8import "nx_sitegen.nx" 9import "nx_syscalls.nx" 10const K_MAGIC_131072: i64 = 131072 11 12func st_slurp(path: *u8, buf: *u8, cap: i64) -> i64 { 13 let fd: i64 = sys_openat_rd(path) 14 if fd < 0 { return 0 - 1 } 15 var total: i64 = 0 16 var go: i64 = 1 17 while go == 1 { 18 let r: i64 = sys_read(fd, buf + total, cap - total) 19 if r <= 0 { go = 0 } 20 if r > 0 { total = total + r } 21 if total >= cap { go = 0 } 22 } 23 sys_close(fd) 24 return total 25} 26 27// build a posted .site blueprint (blob[0..n)) into out (cap); returns output length, or 0 if the engine 28// REFUSED it (not UX-compliant) so the caller can serve a "refused" message. The blueprint is untrusted; 29// nx_sitegen escapes every field, so a hostile blueprint cannot inject markup. (Dev studio: one shared temp 30// build path -- single-user; give each request a unique path before multi-user use.) 31func se_build_site(blob: *u8, n: i64, out: *u8, cap: i64) -> i64 { 32 let kind: *i64 = sys_mmap(8*64) as *i64 33 let a: *i64 = sys_mmap(8*64) as *i64 34 let b: *i64 = sys_mmap(8*64) as *i64 35 let c: *i64 = sys_mmap(8*64) as *i64 36 let d: *i64 = sys_mmap(8*64) as *i64 37 let list: *i64 = sys_mmap(8*64) as *i64 38 let lcount: *i64 = sys_mmap(8*64) as *i64 39 let arena: *u8 = sys_mmap(K_MAGIC_131072) 40 let title: *u8 = sys_mmap(512) 41 let nblk: i64 = sgp_parse(blob, n, kind, a, b, c, d, list, lcount, 64, arena, title, 511) 42 let path: *u8 = "/tmp/nx_studio_build.html" as *u8 43 let fd: i64 = sys_openat_wr(path, 0x1a4) 44 if fd >= 0 { sg_build_page(fd, title, kind, a, b, c, d, list, lcount, nblk); sys_close(fd) } 45 return st_slurp(path, out, cap) 46} 47 48// serve the editor client HTML into out; returns length (or -1 if the asset is missing). 49func se_editor_html(out: *u8, cap: i64) -> i64 { 50 return st_slurp("web_assets/_studio/editor.html" as *u8, out, cap) 51}