code wiki / _hdl_build / nx_galx_viewadd.nx

nx_galx_viewadd.nx source

↩ module page · 80 lines · 3479 B

1// nx_galx_viewadd.nx -- put a cid into the gallery's VIEW index, so the image actually APPEARS. 2// 3// THE THIRD INDEX. Operator, 2026-08-07: *"i also dont see your new gens in nishifamily.com/gallery 4// in the gens area"* -- after I had verified 10/10 served over /img/<cid> and called it done. 5// Both claims were true at once, because the gallery keeps THREE separate indexes: 6// 1. galx_cid_paths.tsv -> galx_cid.idx/.blob RESOLVER (/img/<cid> finds the bytes) 7// 2. galx_view_index.txt ENUMERATOR (what the grid lists) 8// 3. galx_search.tsv SEARCH 9// I fixed (1), proved (1), and shipped. An image in (1) but not (2) is fetchable by anyone who 10// already knows its cid and INVISIBLE to everyone else -- which is the same as not existing. 11// ★★★★★★ "IS IT IN THE INDEX" IS THE WRONG QUESTION. THE QUESTION IS "HOW MANY INDEXES ARE THERE, 12// AND IS IT IN EACH ONE THAT A USER'S PATH GOES THROUGH?" 13// ★ I ASKED WHETHER THE READER COULD RESOLVE IT, NEVER WHETHER ANY READER WOULD EVER ASK. 14// 15// Format, measured not assumed: FIXED-WIDTH 70-byte records = 69-char cid + '\n', and the order is 16// NEWEST-FIRST (verified by resolving record[0] and record[last] to their files and comparing 17// mtimes: 2026-06-14 vs 2026-03-15). So a new gen PREPENDS. Appending would file it as the oldest 18// image in the gallery and bury it under 226,576 others -- technically "added", never seen. 19// 20// Usage: nx_galx_viewadd <view_index> <cid> [<cid> ...] [--apply] 21// license_tier: ORIGINAL 22 23import "nx_syscalls.nx" 24import "nx_strconv.nx" 25 26import "nx_galx_viewadd_lib.nx" 27 28func va_puts(s: *u8) -> i64 { 29 var n: i64 = 0 30 while s[n] != (0 as u8) { n = n + 1 } 31 return sys_write(1, s, n) 32} 33func va_i(v: i64) -> i64 { 34 let b: *u8 = sys_mmap(32) 35 return sys_write(1, b, nx_strconv_format_i64(v, b)) 36} 37 38func main(argc: i64, argv: *i64) -> i64 { 39 if argc < 3 { 40 va_puts("usage: nx_galx_viewadd <view_index> <cid> [<cid> ...] [--apply] 41" as *u8) 42 return 2 43 } 44 let path: *u8 = argv[1] as *u8 45 var apply: i64 = 0 46 var last: i64 = argc 47 let tail: *u8 = argv[argc - 1] as *u8 48 if tail[0] == (0x2D as u8) { apply = 1; last = argc - 1 } 49 50 var added: i64 = 0 51 var dup: i64 = 0 52 var err: i64 = 0 53 var a: i64 = 2 54 while a < last { 55 let c: *u8 = argv[a] as *u8 56 if apply == 0 { 57 // DRY RUN still calls the real presence check, so it cannot disagree with APPLY about 58 // what would happen -- a dry run that uses different code is a different question. 59 let sp: *i64 = sys_mmap(16) as *i64 60 let buf: *u8 = sys_read_file(path, sp) 61 if (buf as i64) == 0 { err = err + 1 } 62 else { 63 if nx_galx_view_present(buf, sp[0], c) == 1 { dup = dup + 1 } else { added = added + 1 } 64 } 65 } else { 66 let r: i64 = nx_galx_view_prepend(path, c) 67 if r == NXV_ADDED { added = added + 1 } 68 else { if r == NXV_PRESENT { dup = dup + 1 } else { err = err + 1 } } 69 } 70 a = a + 1 71 } 72 va_puts("added=" as *u8); va_i(added) 73 va_puts(" already_present=" as *u8); va_i(dup) 74 va_puts(" errors=" as *u8); va_i(err) 75 if apply == 1 { va_puts(" mode=APPLY 76" as *u8) } else { va_puts(" mode=DRY-RUN 77" as *u8) } 78 if err > 0 { return 1 } 79 return 0 80}