code wiki / _hdl_build / nx_gallery_serve.nx

nx_gallery_serve.nx

buildroot/runtime/_hdl_build/nx_gallery_serve.nx

190004 B2617 linesdepth 5pulls 15 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 11 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_cidput.nx nx_galx_shell_jslint.nx nx_prefix.nx nx_galx_sortindex.nx nx_galx_durbin_lib.nx nx_gallery_serve.nx

diagram shows first 10 each side; +1 more imports, +0 more importers in the complete lists below.

imports: nx_syscalls.nxnx_ts_marks.nxnx_search_inverted_persist.nxnx_bm25.nxnx_galx_cid_index.nxnx_galx_cidput.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 nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ 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_munmap 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

structs

174struct NxCidx {
1950struct NxGalIdx {

consts

27const VIEW_MAGIC_2048: i64 = 2048
28const VIEW_MAGIC_2000: i64 = 2000
29const VIEW_MAGIC_1024: i64 = 1024
30const VIEW_MAGIC_1048576: i64 = 1048576
31const VIEW_MAGIC_8388608: i64 = 8388608
32const VIEW_MAGIC_7776000000: i64 = 7776000000
33const VIEW_MAGIC_1000000: i64 = 1000000
34const VIEW_MAGIC_8191: i64 = 8191
35const VIEW_MAGIC_50000000: i64 = 50000000
36const VIEW_MAGIC_262144: i64 = 262144
37const VIEW_MAGIC_262208: i64 = 262208
38const VIEW_MAGIC_4096: i64 = 4096
39const VIEW_MAGIC_1500000: i64 = 1500000
40const VIEW_MAGIC_65536: i64 = 65536
41const VIEW_MAGIC_258000: i64 = 258000
42const VIEW_MAGIC_200000: i64 = 200000
43const VIEW_MAGIC_250000: i64 = 250000
44const VIEW_MAGIC_1100: i64 = 1100
45const VIEW_MAGIC_8192: i64 = 8192
46const VIEW_MAGIC_16384: i64 = 16384
47const VIEW_MAGIC_60000: i64 = 60000
48const VIEW_MAGIC_131072: i64 = 131072
49const VIEW_MAGIC_100000: i64 = 100000
50const VIEW_MAGIC_200008: i64 = 200008
51const VIEW_MAGIC_18090: i64 = 18090
52const VIEW_MAGIC_4194304: i64 = 4194304
54const VIEW_IDX: *u8 = "knowledge/status/galx_view_index.txt" as *u8
55const SEARCH_IDX: *u8 = "knowledge/status/galx_search.tsv" as *u8
56const FAV_LOG: *u8 = "knowledge/status/galx_fav.log" as *u8
57const VIEW_LOG: *u8 = "knowledge/status/galx_views.log" as *u8
58const EVAL_LOG: *u8 = "knowledge/status/eval_lanes.log" as *u8
59const HIDDEN_LOG: *u8 = "knowledge/status/galx_hidden.log" as *u8 // R3 soft-hide: append "<id> <0|1>" (reversible)
60const TAGS_LOG: *u8 = "knowledge/status/galx_tags.log" as *u8 // R4 tags: append "<id>\t<tag>\t<0|1>" (last-wins, additive)
228const GS_THUMB_ELF: *u8 = "/volume1/ai/galx/nx_galx_thumb.elf"
229const GS_THUMB_MAX: *u8 = "384"
290const GS_UPSCALE_ELF: *u8 = "/volume1/ai/galx/nx_galx_upscale.elf"
291const GS_UPSCALE_MODE: *u8 = "one"
292const GS_UPSCALE_FACTOR: *u8 = "2"
297const GS_4CHAN_ELF: *u8 = "/volume1/homes/elderwesto/nishihost/nx_4chan.elf"
298const GS_4CHAN_CWD: *u8 = "/volume1/homes/elderwesto/nishihost"
305const GS_4CHAN_CONF: *u8 = "/volume1/ai/galx/gallery_4chan.conf"
306const GS_4CHAN_MAX_KEY: *u8 = "max_items="
307const GS_4CHAN_MAX_DEF: *u8 = "4096"
447const GS_4C_CACHE_ABS: *u8 = "/volume1/ai/galx/4chan_cache/"
588const GS_4C_ING_DIR: *u8 = "/volume1/homes/elderwesto/nishihost/media/4chan/"
589const GS_4C_JOBS: *u8 = "/volume1/ai/galx/4chan_jobs"
590const GS_MVAULT_ELF: *u8 = "/volume1/homes/elderwesto/nishihost/nx_mvault_walk.elf"
754const GS_4C_REFRESH_S: *u8 = "5"
1660const TELE_LOG: *u8 = "knowledge/status/galx_telemetry.log" as *u8

functions

62func eh_find(buf: *u8, n: i64, pat: *u8, plen: i64) -> i64 {
73func 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 }
74func gs_u(dst: *u8, off: i64, v: i64) -> i64 {
85func gs_strlen(s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){i=i+1} return i }
86func gs_lower(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c }
87func gs_qint(req: *u8, rn: i64, key: *u8, deflt: i64) -> i64 {
104func 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) }
105func gs_okjson(rbuf: *u8, body: *u8, blen: i64) -> i64 {
118func gs_okhtml(rbuf: *u8, body: *u8, blen: i64) -> i64
called by 1: gs_4chan_panel calls 2: gs_catgs_u
131func gs_see_other(rbuf: *u8, loc: *u8) -> i64
called by 1: gs_4chan_ingest calls 1: gs_cat
139func gs_peel_cid(req: *u8, rn: i64, cidout: *u8) -> i64 {
called by 1: gs_serve_png
149func gs_peel_pat(req: *u8, rn: i64, pat: *u8, plen: i64, cidout: *u8) -> i64 {
called by 2: gs_metags_state
159func gs_body_cid(req: *u8, rn: i64, cidout: *u8) -> i64 {
181func gs_sidecar(cidx: *NxCidx, cid: *u8, pathout: *u8) -> i64 {
204func gs_serve_png(rbuf: *u8, req: *u8, rn: i64, cidx: *NxCidx) -> i64 {
232func gs_peel_cid_pat(req: *u8, rn: i64, pat: *u8, plen: i64, cidout: *u8) -> i64 {
called by 2: gs_thumbgs_upscale
242func gs_file_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
244func gs_send_imgfile(rbuf: *u8, path: *u8, ctype: *u8) -> i64 {
259func gs_thumb_run(src: *u8, outnew: *u8) -> i64 {
269func gs_thumb(rbuf: *u8, req: *u8, rn: i64, cidx: *NxCidx) -> i64 {
312func gs_4chan_max(dst: *u8) -> i64
356func gs_4c_peel(req: *u8, rn: i64, s1: *u8, s2: *u8, s3: *u8) -> i64
407func gs_4chan_run(a1: *u8, a2: *u8, a3: *u8, outpath: *u8) -> i64
448func gs_4c_img_peel(req: *u8, rn: i64, board: *u8, file: *u8) -> i64
called by 1: gs_4chan_img
496func gs_4c_isuffix(s: *u8, n: i64, suf: *u8) -> i64
called by 1: gs_4c_ct calls 1: gs_strlen
503func gs_4c_ct(file: *u8) -> *u8
called by 1: gs_4chan_img calls 2: gs_strlengs_4c_isuffix
511func gs_4chan_fetch1(board: *u8, file: *u8, absdir: *u8) -> i64
530func gs_4chan_img(rbuf: *u8, req: *u8, rn: i64) -> i64
547func gs_4chan(rbuf: *u8, req: *u8, rn: i64) -> i64
595func gs_4c_form(req: *u8, rn: i64, key: *u8, dst: *u8, maxlen: i64) -> i64
called by 1: gs_4chan_ingest
626func gs_4c_ingest_work(board: *u8, thread: *u8) -> i64
677func gs_4chan_ingest(rbuf: *u8, req: *u8, rn: i64) -> i64
710func gs_4chan_ingest_status(rbuf: *u8, req: *u8, rn: i64) -> i64
757func gs_4chan_panel(rbuf: *u8, req: *u8, rn: i64) -> i64
816func gs_upscale_run(src: *u8, outnew: *u8) -> i64 {
829func gs_upscale(rbuf: *u8, req: *u8, rn: i64, cidx: *NxCidx) -> i64 {
847func 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 }
848func 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) }
852func gs_vidoff_build() -> i64 {
870func gs_vid_line(id: i64, out: *u8) -> i64 {
917func gs_peel_num(req: *u8, rn: i64, pat: *u8, plen: i64) -> i64 {
927func gs_poster_path(vid: *u8, out: *u8) -> i64 {
called by 1: gs_vidthumb calls 1: gs_strlen
941func gs_vidthumb(rbuf: *u8, req: *u8, rn: i64) -> i64 {
962func 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 }
964func gs_vid_ext(vid: *u8, ex: *u8) -> i64 {
973func gs_vid_mime(ex: *u8) -> *u8 {
called by 1: gs_vid_stream calls 1: gs_streq
980func gs_serve_file_range(cfd: i64, req: *u8, rn: i64, path: *u8, ctype: *u8) -> i64 {
1037func gs_itoa(v: i64, buf: *u8) -> i64 {
1046func gs_pcr_scan(b: *u8, n: i64, fp: *i64, lp: *i64) -> i64 {
called by 1: gs_ts_dur
1061func gs_ts_dur(path: *u8) -> i64 {
1088func gs_vidpaths_size() -> i64 {
1096func gs_vid_dur_reply(cfd: i64, vid: *u8, id: i64) -> i64 {
1108func gs_seek_byte(req: *u8, rn: i64, vid: *u8) -> i64 {
1116func gs_vid_init(cfd: i64, vid: *u8) -> i64 {
1128func 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) }
1129func gs_be64(b: *u8, o: i64) -> i64 { return (gs_be32(b,o)<<32)|(gs_be32(b,o+4)&0xffffffff) }
1130func 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
1131func 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 }
1133func gs_idx_build(id: i64, vid: *u8) -> i64 {
1146func gs_vid_seg(cfd: i64, vid: *u8, sb: i64, eb: i64, base: i64, vpid: i64, apid: i64) -> i64 {
1159func 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
1160func gs_seg_handler(cfd: i64, id: i64, vid: *u8, req: *u8, rn: i64) -> i64 {
1184func 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
1185func gs_segs_handler(cfd: i64, id: i64, vid: *u8) -> i64 {
1200func gs_vid_remux_ts(cfd: i64, vid: *u8, start_byte: i64) -> i64 {
1214func gs_vid_remux_mkv(cfd: i64, vid: *u8, start_byte: i64) -> i64 {
1227func gs_vid_marks(cfd: i64, id: i64) -> i64 {
1263func gs_vid_analysis(cfd: i64, id: i64) -> i64 {
1307func gs_vid_stream(cfd: i64, req: *u8, rn: i64) -> i64 {
1328func gs_path_cat(b: *u8, ls: i64, le: i64, rb: *u8, rsz: i64) -> i64 {
1358func gs_file_size(path: *u8) -> i64 {
1365func gs_catidx_path(wantc: i64, out: *u8) -> i64 {
1371func gs_catidx_write(path: *u8, tsvsz: i64, arr: *i64, cnt: i64) -> i64 {
1383func gs_catidx_build() -> i64 {
1422func gs_eff_offset(req: *u8, rn: i64, count: i64, o0: i64) -> i64 {
1430func gs_catidx_emit(rbuf: *u8, req: *u8, rn: i64, wantc: i64, o0: i64, n: i64) -> i64 {
1452func gs_collection_list(rbuf: *u8, req: *u8, rn: i64, wantc: i64, o0: i64, n: i64) -> i64 {
1501func gs_recordings_list(rbuf: *u8, req: *u8, rn: i64, o0: i64, n: i64) -> i64 {
1546func gs_models(rbuf: *u8) -> i64 {
1576func gs_jesc(dst: *u8, o: i64, ch: i64) -> i64 {
called by 1: gs_meta
1582func gs_meta(rbuf: *u8, req: *u8, rn: i64, cidx: *NxCidx) -> i64 {
1653func gs_append_line(path: *u8, line: *u8, len: i64) -> i64 {
1663func gs_telemetry(rbuf: *u8, req: *u8, rn: i64) -> i64 {
called by 1: main calls 3: sys_mmapgs_append_linegs_cat
1681func gs_same_origin(req: *u8, rn: i64) -> i64 {
1691func 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) }
1692func 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) }
1694func gs_view(rbuf: *u8, req: *u8, rn: i64) -> i64 {
1706func gs_fav(rbuf: *u8, req: *u8, rn: i64) -> i64 {
1732func gs_hide(rbuf: *u8, req: *u8, rn: i64) -> i64 {
1750func gs_hidden_list(rbuf: *u8) -> i64 {
1773func gs_durs_batch(rbuf: *u8, req: *u8, rn: i64) -> i64 {
1792func gs_extract_tag(bp: *u8, bl: i64, out: *u8) -> i64 {
1816func gs_extract_id(bp: *u8, bl: i64, out: *u8) -> i64 {
1833func gs_tag(rbuf: *u8, req: *u8, rn: i64) -> i64 {
1849func gs_tags_get(rbuf: *u8, req: *u8, rn: i64) -> i64 {
1859func gs_tagged_get(rbuf: *u8, req: *u8, rn: i64) -> i64 {
1869func gs_alltags_get(rbuf: *u8, req: *u8, rn: i64) -> i64 {
1876func gs_last_v(path: *u8, cid: *u8) -> i64 {
1895func gs_present(path: *u8, cid: *u8) -> i64 {
1910func gs_last_score(cid: *u8) -> i64 {
1932func gs_state(rbuf: *u8, req: *u8, rn: i64) -> i64 {
1960func gs_bm_doclen(text: *u8, n: i64) -> i64 {
1972func gs_bm_tf(text: *u8, n: i64, th: i64) -> i64 {
1985func gs_galidx_load(gal: *NxGalIdx, idx_path: *u8, manifest_path: *u8) -> i64 {
2017func gs_bm25_emit(rbuf: *u8, gal: *NxGalIdx, qbuf: *u8, qlen: i64, o0: i64, ncount: i64) -> i64 {
2101func gs_emit_cid(body: *u8, o0: i64, first: i64, buf: *u8, pos: i64) -> i64 {
2111func 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 }
2114func gs_filter_list(rbuf: *u8, logpath: *u8, kind: i64, o0: i64, n: i64) -> i64 {
2190func gs_api_suggest(rbuf: *u8, req: *u8, rn: i64) -> i64 {
2226func gs_gens_list(rbuf: *u8, req: *u8, rn: i64, isold: i64, o0: i64, n: i64) -> i64 {
2255func gs_allmedia_list(rbuf: *u8, req: *u8, rn: i64, isold: i64, o0: i64, n: i64) -> i64 {
2310func gs_api_list(rbuf: *u8, req: *u8, rn: i64, gal: *NxGalIdx) -> i64 {
2383func gs_rate(rbuf: *u8, req: *u8, rn: i64) -> i64 {
2411func gs_lora_export(rbuf: *u8, req: *u8, rn: i64) -> i64 {
2434func gs_shell(rbuf: *u8) -> i64 {
2463func gs_spawn_durindex() -> i64 {
2491func main(argc: i64, argv: *i64) -> i64 {