code wiki / _hdl_build / nx_archive_capture.nx
nx_archive_capture.nx source
↩ module page · 25 lines · 1691 B
1// nx_archive_capture.nx -- the CAPTURE step that binds this session's extractor to the WARC store: given a
2// captured page + the media bytes, archive the page AND locate its media URL (nx_media_extract) and archive the
3// media under that exact URL. Result: a self-contained preservation record so that after the origin dies, the
4// search engine retrieves the media by the same URL it indexed. This is the extract->archive half of the
5// sovereign-Browsertrix pipeline (the live-browser render + live download are the network front). ORIGINAL
6import "nx_syscalls.nx"
7import "nx_media_signal.nx"
8import "nx_media_state.nx"
9import "nx_media_extract.nx"
10import "nx_web_archive.nx"
11const K_MAGIC_4096: i64 = 4096
12
13// CAPTURE: archive the page, extract its best media URL, archive the media under that URL. Returns new warc
14// offset; writes the extracted media URL into out_media_url (empty if none found).
15func ac_capture(html: *u8, hlen: i64, page_url: *u8, date: *u8, media_bytes: *u8, media_len: i64, media_ctype: *u8, warc: *u8, off: i64, out_media_url: *u8) -> i64 {
16 off = wa_write_resource(warc, off, page_url, date, "text/html" as *u8, html, hlen) // preserve the page
17 let kb: *i64 = sys_mmap(8) as *i64
18 let best: *u8 = sys_mmap(K_MAGIC_4096)
19 let conf: i64 = mx_extract(html, hlen, best, K_MAGIC_4096, kb) // find its media
20 if conf > 0 {
21 off = wa_write_resource(warc, off, best, date, media_ctype, media_bytes, media_len) // preserve the media
22 var i: i64 = 0; while (best[i]&0xff) != 0 { out_media_url[i] = best[i]; i = i + 1 } out_media_url[i] = 0 as u8
23 } else { out_media_url[0] = 0 as u8 }
24 return off
25}