code wiki / _hdl_build / nx_audio_serve.nx
nx_audio_serve.nx
buildroot/runtime/_hdl_build/nx_audio_serve.nx
about
nx_audio_serve.nx -- the SOVEREIGN audiobook player BRAIN (SC34/35/37), server-side Nishi code (operator: the
player capabilities ARE nishi-code APIs, not browser JS). Binds 127.0.0.1 only. The browser is a dumb native
<audio> client; THIS daemon does the work:
GET /audio/<slug> -> the zero-JS player.html (rendered by nx_audio_render)
GET /audio/<slug>/track -> serve the audio bytes; honors `Range: bytes=X-Y` (206) so <audio> seeks/streams
GET /audio/<slug>/track?sleep=N -> SLEEP TIMER: caps the served stream to N*BYTES_PER_MIN -> playback ends (SC34)
POST /audio/<slug>/bookmark (pos=BYTE) -> stores the position server-side -> 303 (SC35 + SC37 cross-device)
GET /audio/<slug>/resume -> returns the stored position {"pos":N} (the client seeks there) (SC37)
Reuses the proven nx_vizsla_serve HTTP pattern (handle-mode gate hook + gallery_serve socket idiom). The position
store is a per-slug file (reader/<slug>/audio_pos.txt). 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
| 12 | const BYTES_MAGIC_65536: i64 = 65536 |
| 13 | const BYTES_MAGIC_1024: i64 = 1024 |
| 14 | const BYTES_MAGIC_33554432: i64 = 33554432 |
| 15 | const BYTES_MAGIC_18099: i64 = 18099 |
| 19 | const BYTES_PER_MIN: i64 = 100 |
functions
| 21 | func as_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 22 | func as_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){d[o+i]=s[i];i=i+1} return o+i } |
| 23 | func as_catn(d: *u8, o0: i64, v: i64) -> i64 { var o: i64=o0; var m: i64=v; if m<0{d[o]=45 as u8;o=o+1;m=0-m}; 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{d[o+i]=t[k-1-i];i=i+1} return o+k } |
| 24 | func as_match(req: *u8, rn: i64, pat: *u8) -> i64 { let pl: i64=as_slen(pat); if pl>rn{return 0} var j: i64=0; while j<pl{ if req[j]!=pat[j]{return 0} j=j+1 } return 1 } |
| 25 | func as_valid_slug(s: *u8) -> i64 called by 1: handle |
| 31 | func as_readall(path: *u8, szp: *i64) -> *u8 |
| 39 | func parse_range(req: *u8, rn: i64, sp: *i64, ep: *i64) -> i64 |
| 61 | func bodyfield(req: *u8, rn: i64, key: *u8, out: *u8) -> i64 |
| 71 | func parse_route(req: *u8, rn: i64, slug: *u8, action: *u8, sleepp: *i64) -> i64 |
| 90 | func posfile(slug: *u8, out: *u8) -> i64 { var o: i64=as_cat(out,0,"knowledge/staging/media/reader/" as *u8); o=as_cat(out,o,slug); o=as_cat(out,o,"/audio_pos.txt" as *u8); out[o]=0 as u8; return o } |
| 93 | func serve_track(slug: *u8, has_range: i64, rs: i64, re0: i64, sleep_min: i64, rbuf: *u8) -> i64 |
| 119 | func handle(req: *u8, rn: i64, rbuf: *u8) -> i64 |
| 159 | func main(argc: i64, argv: *i64) -> i64 |