code wiki / _hdl_build / nx_gallery_serve.nx
nx_gallery_serve.nx
buildroot/runtime/_hdl_build/nx_gallery_serve.nx
about
nx_gallery_serve.nx -- SOVEREIGN Nishi image-library gallery daemon (port 18090). Pinterest-style masonry
of the FULL-RESOLUTION images (no thumbnails) with infinite scroll, sort, search, and STATE FILTERS:
viewed (clicked), rated, and favorite. Favorite = the LoRA-training flag (knowledge/status/galx_fav.log
is the training candidate set a downstream LoRA/i2i pipeline consumes). Clicking opens the lossless image
with the generation-factor panel and a rating control; opening marks it viewed.
GET / -> gallery shell (masonry + infinite scroll + filters + lightbox)
GET /api/list?o=&n=&s=&q=&filter= -> {"total":N,"items":[cid...]} (filter=all|fav|rated|viewed)
GET /img/<cid> -> full-resolution lossless source PNG
GET /meta/<cid> -> {factor:value,...} from the PNG tEXt/iTXt
GET /state/<cid> -> {"fav":0|1,"rating":N,"viewed":0|1}
POST /view img= -> mark viewed (append galx_views.log)
POST /fav img=&v= -> set favorite 0/1 (append galx_fav.log) [LoRA-training flag]
POST /rate img=&score= -> append one EVAL O-line
All logic is NishiLang; bash is only ever a launcher. license_tier: ORIGINAL
dependencies 10 imports · 0 importers
imports: nx_syscalls.nxnx_ts_marks.nxnx_search_inverted_persist.nxnx_bm25.nxnx_galx_cid_index.nxnx_galx_shell_jslint.nxnx_prefix.nxnx_galx_sortindex.nxnx_galx_durbin_lib.nxnx_galx_tags.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 149 | struct NxCidx |
| 1403 | struct NxGalIdx |
consts
| 26 | const VIEW_MAGIC_2048: i64 = 2048 |
| 27 | const VIEW_MAGIC_2000: i64 = 2000 |
| 28 | const VIEW_MAGIC_1024: i64 = 1024 |
| 29 | const VIEW_MAGIC_1048576: i64 = 1048576 |
| 30 | const VIEW_MAGIC_8388608: i64 = 8388608 |
| 31 | const VIEW_MAGIC_7776000000: i64 = 7776000000 |
| 32 | const VIEW_MAGIC_1000000: i64 = 1000000 |
| 33 | const VIEW_MAGIC_8191: i64 = 8191 |
| 34 | const VIEW_MAGIC_50000000: i64 = 50000000 |
| 35 | const VIEW_MAGIC_262144: i64 = 262144 |
| 36 | const VIEW_MAGIC_262208: i64 = 262208 |
| 37 | const VIEW_MAGIC_4096: i64 = 4096 |
| 38 | const VIEW_MAGIC_1500000: i64 = 1500000 |
| 39 | const VIEW_MAGIC_65536: i64 = 65536 |
| 40 | const VIEW_MAGIC_258000: i64 = 258000 |
| 41 | const VIEW_MAGIC_200000: i64 = 200000 |
| 42 | const VIEW_MAGIC_250000: i64 = 250000 |
| 43 | const VIEW_MAGIC_1100: i64 = 1100 |
| 44 | const VIEW_MAGIC_8192: i64 = 8192 |
| 45 | const VIEW_MAGIC_16384: i64 = 16384 |
| 46 | const VIEW_MAGIC_60000: i64 = 60000 |
| 47 | const VIEW_MAGIC_131072: i64 = 131072 |
| 48 | const VIEW_MAGIC_100000: i64 = 100000 |
| 49 | const VIEW_MAGIC_200008: i64 = 200008 |
| 50 | const VIEW_MAGIC_18090: i64 = 18090 |
| 51 | const VIEW_MAGIC_4194304: i64 = 4194304 |
| 53 | const VIEW_IDX: *u8 = "knowledge/status/galx_view_index.txt" as *u8 |
| 54 | const SEARCH_IDX: *u8 = "knowledge/status/galx_search.tsv" as *u8 |
| 55 | const FAV_LOG: *u8 = "knowledge/status/galx_fav.log" as *u8 |
| 56 | const VIEW_LOG: *u8 = "knowledge/status/galx_views.log" as *u8 |
| 57 | const EVAL_LOG: *u8 = "knowledge/status/eval_lanes.log" as *u8 |
| 58 | const HIDDEN_LOG: *u8 = "knowledge/status/galx_hidden.log" as *u8 // R3 soft-hide: append "<id> <0|1>" (reversible) |
| 59 | const TAGS_LOG: *u8 = "knowledge/status/galx_tags.log" as *u8 // R4 tags: append "<id>\t<tag>\t<0|1>" (last-wins, additive) |
| 203 | const GS_THUMB_ELF: *u8 = "/volume1/ai/galx/nx_galx_thumb.elf" |
| 204 | const GS_THUMB_MAX: *u8 = "384" |
| 265 | const GS_UPSCALE_ELF: *u8 = "/volume1/ai/galx/nx_galx_upscale.elf" |
| 266 | const GS_UPSCALE_MODE: *u8 = "one" |
| 267 | const GS_UPSCALE_FACTOR: *u8 = "2" |
| 1113 | const TELE_LOG: *u8 = "knowledge/status/galx_telemetry.log" as *u8 |
functions
| 61 | func eh_find(buf: *u8, n: i64, pat: *u8, plen: i64) -> i64 |
| 72 | func gs_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 } |
| 73 | func gs_u(dst: *u8, off: i64, v: i64) -> i64 called by 19: gs_okjsongs_serve_pnggs_send_imgfilegs_vidthumbgs_serve_file_rangegs_vid_dur_reply+13 calls 1: sys_mmap |
| 84 | func gs_strlen(s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){i=i+1} return i } |
| 85 | func gs_lower(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c } |
| 86 | func gs_qint(req: *u8, rn: i64, key: *u8, deflt: i64) -> i64 |
| 103 | func gs_404(rbuf: *u8) -> i64 { return gs_cat(rbuf, 0, "HTTP/1.1 404 Not Found\r\nContent-Type: text/plain\r\nContent-Length: 9\r\nConnection: close\r\n\r\nnot found" as *u8) } |
| 104 | func gs_okjson(rbuf: *u8, body: *u8, blen: i64) -> i64 called by 21: gs_segs_handlergs_vid_marksgs_vid_analysisgs_catidx_emitgs_collection_listgs_recordings_list+15 calls 2: gs_catgs_u |
| 114 | func gs_peel_cid(req: *u8, rn: i64, cidout: *u8) -> i64 called by 1: gs_serve_png |
| 124 | func gs_peel_pat(req: *u8, rn: i64, pat: *u8, plen: i64, cidout: *u8) -> i64 |
| 134 | func gs_body_cid(req: *u8, rn: i64, cidout: *u8) -> i64 |
| 156 | func gs_sidecar(cidx: *NxCidx, cid: *u8, pathout: *u8) -> i64 |
| 179 | func gs_serve_png(rbuf: *u8, req: *u8, rn: i64, cidx: *NxCidx) -> i64 |
| 207 | func gs_peel_cid_pat(req: *u8, rn: i64, pat: *u8, plen: i64, cidout: *u8) -> i64 |
| 217 | func gs_file_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } |
| 219 | func gs_send_imgfile(rbuf: *u8, path: *u8, ctype: *u8) -> i64 |
| 234 | func gs_thumb_run(src: *u8, outnew: *u8) -> i64 |
| 244 | func gs_thumb(rbuf: *u8, req: *u8, rn: i64, cidx: *NxCidx) -> i64 |
| 269 | func gs_upscale_run(src: *u8, outnew: *u8) -> i64 |
| 282 | func gs_upscale(rbuf: *u8, req: *u8, rn: i64, cidx: *NxCidx) -> i64 |
| 300 | func gs_wb64(b: *u8, o: i64, v: i64) -> i64 { b[o]=((v>>56)&0xff) as u8; b[o+1]=((v>>48)&0xff) as u8; b[o+2]=((v>>40)&0xff) as u8; b[o+3]=((v>>32)&0xff) as u8; b[o+4]=((v>>24)&0xff) as u8; b[o+5]=((v>>16)&0xff) as u8; b[o+6]=((v>>8)&0xff) as u8; b[o+7]=(v&0xff) as u8; return o+8 } |
| 301 | func gs_rb64(b: *u8, o: i64) -> i64 { return ((b[o] as i64)<<56)|((b[o+1] as i64)<<48)|((b[o+2] as i64)<<40)|((b[o+3] as i64)<<32)|((b[o+4] as i64)<<24)|((b[o+5] as i64)<<16)|((b[o+6] as i64)<<8)|(b[o+7] as i64) } |
| 305 | func gs_vidoff_build() -> i64 |
| 323 | func gs_vid_line(id: i64, out: *u8) -> i64 called by 2: gs_vidthumbgs_vid_stream calls 7: sys_openat_rdsys_mmapsys_readgs_rb64sys_lseeksys_close+1 |
| 370 | func gs_peel_num(req: *u8, rn: i64, pat: *u8, plen: i64) -> i64 |
| 380 | func gs_poster_path(vid: *u8, out: *u8) -> i64 |
| 394 | func gs_vidthumb(rbuf: *u8, req: *u8, rn: i64) -> i64 |
| 415 | func gs_streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8) { if a[i]!=b[i] { return 0 } i=i+1 } if b[i]!=(0 as u8) { return 0 } return 1 } |
| 417 | func gs_vid_ext(vid: *u8, ex: *u8) -> i64 |
| 426 | func gs_vid_mime(ex: *u8) -> *u8 |
| 433 | func gs_serve_file_range(cfd: i64, req: *u8, rn: i64, path: *u8, ctype: *u8) -> i64 |
| 490 | func gs_itoa(v: i64, buf: *u8) -> i64 |
| 499 | func gs_pcr_scan(b: *u8, n: i64, fp: *i64, lp: *i64) -> i64 called by 1: gs_ts_dur |
| 514 | func gs_ts_dur(path: *u8) -> i64 |
| 541 | func gs_vidpaths_size() -> i64 |
| 549 | func gs_vid_dur_reply(cfd: i64, vid: *u8, id: i64) -> i64 |
| 561 | func gs_seek_byte(req: *u8, rn: i64, vid: *u8) -> i64 |
| 569 | func gs_vid_init(cfd: i64, vid: *u8) -> i64 |
| 581 | func gs_be32(b: *u8, o: i64) -> i64 { return ((b[o] as i64)<<24)|((b[o+1] as i64)<<16)|((b[o+2] as i64)<<8)|(b[o+3] as i64) } |
| 582 | func gs_be64(b: *u8, o: i64) -> i64 { return (gs_be32(b,o)<<32)|(gs_be32(b,o+4)&0xffffffff) } |
| 583 | func gs_hex2(b: *u8, o: i64, v: i64) -> i64 { let h: *u8="0123456789abcdef" as *u8; b[o]=h[(v>>4)&0xf]; b[o+1]=h[v&0xf]; return o+2 } called by 1: gs_segs_handler |
| 584 | func gs_idxpath(id: i64, buf: *u8) -> i64 { var o: i64=gs_cat(buf,0,"knowledge/status/galxidx_" as *u8); let d: *u8=sys_mmap(32); let dl: i64=gs_itoa(id,d); var k: i64=0; while k<dl { buf[o]=d[k]; o=o+1; k=k+1 } o=gs_cat(buf,o,".idx" as *u8); buf[o]=0 as u8; return o } called by 5: gs_idx_buildgs_seg_handlergs_segs_handlergs_vid_marksgs_vid_analysis calls 3: gs_catsys_mmapgs_itoa |
| 586 | func gs_idx_build(id: i64, vid: *u8) -> i64 called by 2: gs_seg_handlergs_segs_handler calls 5: sys_forksys_mmapgs_idxpathsys_execve_cleansys_exit |
| 599 | func gs_vid_seg(cfd: i64, vid: *u8, sb: i64, eb: i64, base: i64, vpid: i64, apid: i64) -> i64 |
| 612 | func gs_503(cfd: i64) -> i64 { let m: *u8="HTTP/1.1 503 Service Unavailable\r\nContent-Type: text/plain\r\nCache-Control: no-store\r\nContent-Length: 8\r\nConnection: close\r\n\r\nbuilding" as *u8; sys_write(cfd, m, gs_strlen(m)); return 1 } |
| 613 | func gs_seg_handler(cfd: i64, id: i64, vid: *u8, req: *u8, rn: i64) -> i64 |
| 637 | func gs_vid_native(ex: *u8) -> i64 { if gs_streq(ex,"mp4" as *u8)==1 {return 1} if gs_streq(ex,"m4v" as *u8)==1 {return 1} if gs_streq(ex,"mov" as *u8)==1 {return 1} if gs_streq(ex,"webm" as *u8)==1 {return 1} return 0 } |
| 638 | func gs_segs_handler(cfd: i64, id: i64, vid: *u8) -> i64 |
| 653 | func gs_vid_remux_ts(cfd: i64, vid: *u8, start_byte: i64) -> i64 |
| 667 | func gs_vid_remux_mkv(cfd: i64, vid: *u8, start_byte: i64) -> i64 |
| 680 | func gs_vid_marks(cfd: i64, id: i64) -> i64 |
| 716 | func gs_vid_analysis(cfd: i64, id: i64) -> i64 |
| 760 | func gs_vid_stream(cfd: i64, req: *u8, rn: i64) -> i64 |
| 781 | func gs_path_cat(b: *u8, ls: i64, le: i64, rb: *u8, rsz: i64) -> i64 |
| 811 | func gs_file_size(path: *u8) -> i64 |
| 818 | func gs_catidx_path(wantc: i64, out: *u8) -> i64 |
| 824 | func gs_catidx_write(path: *u8, tsvsz: i64, arr: *i64, cnt: i64) -> i64 |
| 836 | func gs_catidx_build() -> i64 |
| 875 | func gs_eff_offset(req: *u8, rn: i64, count: i64, o0: i64) -> i64 |
| 883 | func gs_catidx_emit(rbuf: *u8, req: *u8, rn: i64, wantc: i64, o0: i64, n: i64) -> i64 called by 1: gs_collection_list calls 9: gs_file_sizesys_mmapgs_catidx_pathsys_read_filegs_rb64gs_eff_offset+3 |
| 905 | func gs_collection_list(rbuf: *u8, req: *u8, rn: i64, wantc: i64, o0: i64, n: i64) -> i64 |
| 954 | func gs_recordings_list(rbuf: *u8, req: *u8, rn: i64, o0: i64, n: i64) -> i64 |
| 999 | func gs_models(rbuf: *u8) -> i64 |
| 1029 | func gs_jesc(dst: *u8, o: i64, ch: i64) -> i64 called by 1: gs_meta |
| 1035 | func gs_meta(rbuf: *u8, req: *u8, rn: i64, cidx: *NxCidx) -> i64 |
| 1106 | func gs_append_line(path: *u8, line: *u8, len: i64) -> i64 called by 6: gs_telemetrygs_viewgs_favgs_hidegs_taggs_rate calls 3: sys_openat_appendsys_writesys_close |
| 1116 | func gs_telemetry(rbuf: *u8, req: *u8, rn: i64) -> i64 |
| 1134 | func gs_same_origin(req: *u8, rn: i64) -> i64 |
| 1144 | func gs_forbidden(rbuf: *u8) -> i64 { return gs_cat(rbuf, 0, "HTTP/1.1 403 Forbidden\r\nContent-Type: text/plain\r\nContent-Length: 9\r\nConnection: close\r\n\r\nforbidden" as *u8) } |
| 1145 | func gs_okrate(rbuf: *u8) -> i64 { return gs_cat(rbuf, 0, "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 2\r\nConnection: close\r\n\r\nok" as *u8) } |
| 1147 | func gs_view(rbuf: *u8, req: *u8, rn: i64) -> i64 |
| 1159 | func gs_fav(rbuf: *u8, req: *u8, rn: i64) -> i64 |
| 1185 | func gs_hide(rbuf: *u8, req: *u8, rn: i64) -> i64 |
| 1226 | func gs_durs_batch(rbuf: *u8, req: *u8, rn: i64) -> i64 |
| 1245 | func gs_extract_tag(bp: *u8, bl: i64, out: *u8) -> i64 |
| 1269 | func gs_extract_id(bp: *u8, bl: i64, out: *u8) -> i64 |
| 1286 | func gs_tag(rbuf: *u8, req: *u8, rn: i64) -> i64 |
| 1302 | func gs_tags_get(rbuf: *u8, req: *u8, rn: i64) -> i64 |
| 1312 | func gs_tagged_get(rbuf: *u8, req: *u8, rn: i64) -> i64 |
| 1322 | func gs_alltags_get(rbuf: *u8, req: *u8, rn: i64) -> i64 |
| 1329 | func gs_last_v(path: *u8, cid: *u8) -> i64 |
| 1348 | func gs_present(path: *u8, cid: *u8) -> i64 |
| 1363 | func gs_last_score(cid: *u8) -> i64 |
| 1385 | func gs_state(rbuf: *u8, req: *u8, rn: i64) -> i64 |
| 1413 | func gs_bm_doclen(text: *u8, n: i64) -> i64 |
| 1425 | func gs_bm_tf(text: *u8, n: i64, th: i64) -> i64 |
| 1438 | func gs_galidx_load(gal: *NxGalIdx, idx_path: *u8, manifest_path: *u8) -> i64 |
| 1470 | func gs_bm25_emit(rbuf: *u8, gal: *NxGalIdx, qbuf: *u8, qlen: i64, o0: i64, ncount: i64) -> i64 |
| 1554 | func gs_emit_cid(body: *u8, o0: i64, first: i64, buf: *u8, pos: i64) -> i64 |
| 1564 | func gs_cideq2(a: *u8, ao: i64, b: *u8, bo: i64) -> i64 { var k: i64=0; while k<69 { if a[ao+k]!=b[bo+k] { return 0 } k=k+1 } return 1 } |
| 1567 | func gs_filter_list(rbuf: *u8, logpath: *u8, kind: i64, o0: i64, n: i64) -> i64 |
| 1643 | func gs_api_suggest(rbuf: *u8, req: *u8, rn: i64) -> i64 |
| 1679 | func gs_gens_list(rbuf: *u8, req: *u8, rn: i64, isold: i64, o0: i64, n: i64) -> i64 |
| 1708 | func gs_allmedia_list(rbuf: *u8, req: *u8, rn: i64, isold: i64, o0: i64, n: i64) -> i64 |
| 1763 | func gs_api_list(rbuf: *u8, req: *u8, rn: i64, gal: *NxGalIdx) -> i64 |
| 1836 | func gs_rate(rbuf: *u8, req: *u8, rn: i64) -> i64 |
| 1864 | func gs_lora_export(rbuf: *u8, req: *u8, rn: i64) -> i64 |
| 1887 | func gs_shell(rbuf: *u8) -> i64 |
| 1914 | func gs_spawn_durindex() -> i64 |
| 1942 | func main(argc: i64, argv: *i64) -> i64 |