code wiki / _hdl_build / nx_imgbook_promote.nx
nx_imgbook_promote.nx
buildroot/runtime/_hdl_build/nx_imgbook_promote.nx
about
nx_imgbook_promote.nx -- promote an ALREADY-EXTRACTED image-dominant book to the CBX/zoom viewer.
GROUND TRUTH driving this organ (operator slug ba4e3a12c8d2091): a Kindle/EPUB COMIC extracts as
~190 full-res JPEGs + ~190 text "chapters" of 33-215 BYTES each (image-anchor stubs). The text
reader then shows 190 empty chapters = "the book doesn't load". The images are ALREADY on disk --
no re-extraction needed. This organ inspects reader/<slug>/, and IF the book is image-dominant
(>= IB_MIN_IMAGES real image files AND avg chapter text < IB_MAX_AVG_CHAP bytes), writes cbx.json
(natural-sorted pages, "cfix":2) so /api/open routes it to the ZOOM viewer. A text book is left
untouched (exit 2). Idempotent: re-running overwrites the same cbx.json.
argv: nx_imgbook_promote <bookpath-ignored> <slug> (matches ms_run_extractor's <path> <slug> shape)
exit: 0 promoted (cbx.json written) | 2 not an image-book (honest skip) | 1 error
license_tier: ORIGINAL
dependencies 1 imports · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 15 | const IB_MAGIC_1048576: i64 = 1048576 |
| 16 | const IB_MAGIC_65536: i64 = 65536 |
| 17 | const IB_MAGIC_1024: i64 = 1024 |
| 18 | const IB_MAGIC_999999: i64 = 999999 |
| 20 | const IB_MIN_IMAGES: i64 = 8 // fewer real images than this = a text book with plates, not a comic |
| 21 | const IB_MAX_AVG_CHAP: i64 = 300 // avg chapter bytes at/under this = image-anchor stubs, not prose |
| 149 | const IB_ECAP: i64 = 4096 |
functions
| 23 | func ib_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 24 | func ib_w(fd: i64, s: *u8) -> i64 { sys_write(fd, s, ib_slen(s)); return 0 } |
| 25 | func ib_n(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(fd,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1}; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(fd,bb,k); return 0 } |
| 26 | func ib_p(s: *u8) -> i64 { ib_w(1, s); return 0 } |
| 27 | func ib_pn(v: i64) -> i64 { ib_n(1, v); return 0 } |
| 28 | func ib_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){dst[off+i]=s[i];i=i+1} return off+i } called by 1: main |
| 30 | func ib_lc(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c } |
| 33 | func ib_is_image(name: *u8) -> i64 |
| 52 | func ib_is_derived(name: *u8) -> i64 |
| 62 | func ib_is_chap(name: *u8) -> i64 |
| 77 | func ib_fsize(path: *u8) -> i64 |
| 84 | func nat_digits(s: *u8, o: i64) -> i64 called by 1: name_cmp_nat |
| 97 | func name_cmp_nat(a: *u8, b: *u8) -> i64 |
| 151 | func main(argc: i64, argv: *i64) -> i64 |