code wiki / _hdl_build / nx_gallery_serve.nx

nx_gallery_serve.nx

buildroot/runtime/_hdl_build/nx_gallery_serve.nx

153759 B2044 linesdepth 5pulls 14 transitivereach 0 importersview sourcekind servicetopic gallery
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_ts_marks.nx nx_search_inverted_persist.nx nx_bm25.nx nx_galx_cid_index.nx nx_galx_shell_jslint.nx nx_prefix.nx nx_galx_sortindex.nx nx_galx_durbin_lib.nx nx_galx_tags.nx nx_gallery_serve.nx

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

main sys_mmap sys_socket sys_setsockopt sys_bind sys_listen gs_vidoff_build sys_mmap ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close gs_wb64 sys_openat_wr sys_write sys_close ↻ sys_fork gs_catidx_build sys_mmap ↻ sys_read_file ↻ gs_path_cat gs_catidx_path gs_cat gs_catidx_write sys_mmap ↻ gs_wb64 ↻ sys_openat_wr ↻ sys_write ↻ sys_close ↻ sys_exit sys_wait4 gs_cidindex_build sys_mmap ↻ sys_read_file ↻ cidx_fnv1a sys_openat_wr ↻ sys_write ↻ sys_close ↻

structs

149struct NxCidx
1403struct NxGalIdx

consts

26const VIEW_MAGIC_2048: i64 = 2048
27const VIEW_MAGIC_2000: i64 = 2000
28const VIEW_MAGIC_1024: i64 = 1024
29const VIEW_MAGIC_1048576: i64 = 1048576
30const VIEW_MAGIC_8388608: i64 = 8388608
31const VIEW_MAGIC_7776000000: i64 = 7776000000
32const VIEW_MAGIC_1000000: i64 = 1000000
33const VIEW_MAGIC_8191: i64 = 8191
34const VIEW_MAGIC_50000000: i64 = 50000000
35const VIEW_MAGIC_262144: i64 = 262144
36const VIEW_MAGIC_262208: i64 = 262208
37const VIEW_MAGIC_4096: i64 = 4096
38const VIEW_MAGIC_1500000: i64 = 1500000
39const VIEW_MAGIC_65536: i64 = 65536
40const VIEW_MAGIC_258000: i64 = 258000
41const VIEW_MAGIC_200000: i64 = 200000
42const VIEW_MAGIC_250000: i64 = 250000
43const VIEW_MAGIC_1100: i64 = 1100
44const VIEW_MAGIC_8192: i64 = 8192
45const VIEW_MAGIC_16384: i64 = 16384
46const VIEW_MAGIC_60000: i64 = 60000
47const VIEW_MAGIC_131072: i64 = 131072
48const VIEW_MAGIC_100000: i64 = 100000
49const VIEW_MAGIC_200008: i64 = 200008
50const VIEW_MAGIC_18090: i64 = 18090
51const VIEW_MAGIC_4194304: i64 = 4194304
53const VIEW_IDX: *u8 = "knowledge/status/galx_view_index.txt" as *u8
54const SEARCH_IDX: *u8 = "knowledge/status/galx_search.tsv" as *u8
55const FAV_LOG: *u8 = "knowledge/status/galx_fav.log" as *u8
56const VIEW_LOG: *u8 = "knowledge/status/galx_views.log" as *u8
57const EVAL_LOG: *u8 = "knowledge/status/eval_lanes.log" as *u8
58const HIDDEN_LOG: *u8 = "knowledge/status/galx_hidden.log" as *u8 // R3 soft-hide: append "<id> <0|1>" (reversible)
59const TAGS_LOG: *u8 = "knowledge/status/galx_tags.log" as *u8 // R4 tags: append "<id>\t<tag>\t<0|1>" (last-wins, additive)
203const GS_THUMB_ELF: *u8 = "/volume1/ai/galx/nx_galx_thumb.elf"
204const GS_THUMB_MAX: *u8 = "384"
265const GS_UPSCALE_ELF: *u8 = "/volume1/ai/galx/nx_galx_upscale.elf"
266const GS_UPSCALE_MODE: *u8 = "one"
267const GS_UPSCALE_FACTOR: *u8 = "2"
1113const TELE_LOG: *u8 = "knowledge/status/galx_telemetry.log" as *u8

functions

61func eh_find(buf: *u8, n: i64, pat: *u8, plen: i64) -> i64
72func 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 }
73func gs_u(dst: *u8, off: i64, v: i64) -> i64
84func gs_strlen(s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){i=i+1} return i }
85func gs_lower(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c }
86func gs_qint(req: *u8, rn: i64, key: *u8, deflt: i64) -> i64
103func 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) }
104func gs_okjson(rbuf: *u8, body: *u8, blen: i64) -> i64
114func gs_peel_cid(req: *u8, rn: i64, cidout: *u8) -> i64
called by 1: gs_serve_png
124func gs_peel_pat(req: *u8, rn: i64, pat: *u8, plen: i64, cidout: *u8) -> i64
called by 2: gs_metags_state
134func gs_body_cid(req: *u8, rn: i64, cidout: *u8) -> i64
156func gs_sidecar(cidx: *NxCidx, cid: *u8, pathout: *u8) -> i64
179func gs_serve_png(rbuf: *u8, req: *u8, rn: i64, cidx: *NxCidx) -> i64
207func gs_peel_cid_pat(req: *u8, rn: i64, pat: *u8, plen: i64, cidout: *u8) -> i64
called by 2: gs_thumbgs_upscale
217func gs_file_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
219func gs_send_imgfile(rbuf: *u8, path: *u8, ctype: *u8) -> i64
234func gs_thumb_run(src: *u8, outnew: *u8) -> i64
244func gs_thumb(rbuf: *u8, req: *u8, rn: i64, cidx: *NxCidx) -> i64
269func gs_upscale_run(src: *u8, outnew: *u8) -> i64
282func gs_upscale(rbuf: *u8, req: *u8, rn: i64, cidx: *NxCidx) -> i64
300func 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 }
301func 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) }
305func gs_vidoff_build() -> i64
323func gs_vid_line(id: i64, out: *u8) -> i64
370func gs_peel_num(req: *u8, rn: i64, pat: *u8, plen: i64) -> i64
380func gs_poster_path(vid: *u8, out: *u8) -> i64
called by 1: gs_vidthumb calls 1: gs_strlen
394func gs_vidthumb(rbuf: *u8, req: *u8, rn: i64) -> i64
415func 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 }
417func gs_vid_ext(vid: *u8, ex: *u8) -> i64
426func gs_vid_mime(ex: *u8) -> *u8
called by 1: gs_vid_stream calls 1: gs_streq
433func gs_serve_file_range(cfd: i64, req: *u8, rn: i64, path: *u8, ctype: *u8) -> i64
490func gs_itoa(v: i64, buf: *u8) -> i64
499func gs_pcr_scan(b: *u8, n: i64, fp: *i64, lp: *i64) -> i64
called by 1: gs_ts_dur
514func gs_ts_dur(path: *u8) -> i64
541func gs_vidpaths_size() -> i64
549func gs_vid_dur_reply(cfd: i64, vid: *u8, id: i64) -> i64
561func gs_seek_byte(req: *u8, rn: i64, vid: *u8) -> i64
569func gs_vid_init(cfd: i64, vid: *u8) -> i64
581func 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) }
582func gs_be64(b: *u8, o: i64) -> i64 { return (gs_be32(b,o)<<32)|(gs_be32(b,o+4)&0xffffffff) }
583func 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
584func 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 }
586func gs_idx_build(id: i64, vid: *u8) -> i64
599func gs_vid_seg(cfd: i64, vid: *u8, sb: i64, eb: i64, base: i64, vpid: i64, apid: i64) -> i64
612func 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 }
called by 1: gs_seg_handler calls 2: sys_writegs_strlen
613func gs_seg_handler(cfd: i64, id: i64, vid: *u8, req: *u8, rn: i64) -> i64
637func 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 }
called by 1: gs_segs_handler calls 1: gs_streq
638func gs_segs_handler(cfd: i64, id: i64, vid: *u8) -> i64
653func gs_vid_remux_ts(cfd: i64, vid: *u8, start_byte: i64) -> i64
667func gs_vid_remux_mkv(cfd: i64, vid: *u8, start_byte: i64) -> i64
680func gs_vid_marks(cfd: i64, id: i64) -> i64
716func gs_vid_analysis(cfd: i64, id: i64) -> i64
760func gs_vid_stream(cfd: i64, req: *u8, rn: i64) -> i64
781func gs_path_cat(b: *u8, ls: i64, le: i64, rb: *u8, rsz: i64) -> i64
811func gs_file_size(path: *u8) -> i64
818func gs_catidx_path(wantc: i64, out: *u8) -> i64
824func gs_catidx_write(path: *u8, tsvsz: i64, arr: *i64, cnt: i64) -> i64
836func gs_catidx_build() -> i64
875func gs_eff_offset(req: *u8, rn: i64, count: i64, o0: i64) -> i64
883func gs_catidx_emit(rbuf: *u8, req: *u8, rn: i64, wantc: i64, o0: i64, n: i64) -> i64
905func gs_collection_list(rbuf: *u8, req: *u8, rn: i64, wantc: i64, o0: i64, n: i64) -> i64
954func gs_recordings_list(rbuf: *u8, req: *u8, rn: i64, o0: i64, n: i64) -> i64
999func gs_models(rbuf: *u8) -> i64
1029func gs_jesc(dst: *u8, o: i64, ch: i64) -> i64
called by 1: gs_meta
1035func gs_meta(rbuf: *u8, req: *u8, rn: i64, cidx: *NxCidx) -> i64
1106func gs_append_line(path: *u8, line: *u8, len: i64) -> i64
1116func gs_telemetry(rbuf: *u8, req: *u8, rn: i64) -> i64
called by 1: main calls 3: sys_mmapgs_append_linegs_cat
1134func gs_same_origin(req: *u8, rn: i64) -> i64
1144func 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) }
1145func 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) }
1147func gs_view(rbuf: *u8, req: *u8, rn: i64) -> i64
1159func gs_fav(rbuf: *u8, req: *u8, rn: i64) -> i64
1185func gs_hide(rbuf: *u8, req: *u8, rn: i64) -> i64
1203func gs_hidden_list(rbuf: *u8) -> i64
1226func gs_durs_batch(rbuf: *u8, req: *u8, rn: i64) -> i64
1245func gs_extract_tag(bp: *u8, bl: i64, out: *u8) -> i64
1269func gs_extract_id(bp: *u8, bl: i64, out: *u8) -> i64
1286func gs_tag(rbuf: *u8, req: *u8, rn: i64) -> i64
1302func gs_tags_get(rbuf: *u8, req: *u8, rn: i64) -> i64
1312func gs_tagged_get(rbuf: *u8, req: *u8, rn: i64) -> i64
1322func gs_alltags_get(rbuf: *u8, req: *u8, rn: i64) -> i64
1329func gs_last_v(path: *u8, cid: *u8) -> i64
1348func gs_present(path: *u8, cid: *u8) -> i64
1363func gs_last_score(cid: *u8) -> i64
1385func gs_state(rbuf: *u8, req: *u8, rn: i64) -> i64
1413func gs_bm_doclen(text: *u8, n: i64) -> i64
1425func gs_bm_tf(text: *u8, n: i64, th: i64) -> i64
1438func gs_galidx_load(gal: *NxGalIdx, idx_path: *u8, manifest_path: *u8) -> i64
1470func gs_bm25_emit(rbuf: *u8, gal: *NxGalIdx, qbuf: *u8, qlen: i64, o0: i64, ncount: i64) -> i64
1554func gs_emit_cid(body: *u8, o0: i64, first: i64, buf: *u8, pos: i64) -> i64
1564func 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 }
1567func gs_filter_list(rbuf: *u8, logpath: *u8, kind: i64, o0: i64, n: i64) -> i64
1643func gs_api_suggest(rbuf: *u8, req: *u8, rn: i64) -> i64
1679func gs_gens_list(rbuf: *u8, req: *u8, rn: i64, isold: i64, o0: i64, n: i64) -> i64
1708func gs_allmedia_list(rbuf: *u8, req: *u8, rn: i64, isold: i64, o0: i64, n: i64) -> i64
1763func gs_api_list(rbuf: *u8, req: *u8, rn: i64, gal: *NxGalIdx) -> i64
1836func gs_rate(rbuf: *u8, req: *u8, rn: i64) -> i64
1864func gs_lora_export(rbuf: *u8, req: *u8, rn: i64) -> i64
1887func gs_shell(rbuf: *u8) -> i64
1914func gs_spawn_durindex() -> i64
1942func main(argc: i64, argv: *i64) -> i64