code wiki / wiki / nx_wiki_edit_handler.nx

nx_wiki_edit_handler.nx

buildroot/runtime/wiki/nx_wiki_edit_handler.nx

15575 B354 linesdepth 16pulls 51 transitivereach 7 importersview sourcekind librarytopic wiki
docsdependenciesstructsconstsfunctions

about

nx_wiki_edit_handler.nx -- wiki R1: GET/POST /wiki/<slug>/edit HTTP handlers. The thin HTTP adapter over nx_wiki_page_save (the auth-gated persist core): GET /wiki/<slug>/edit -> 200 an HTML <form> pre-filled with the current markdown (AUTH-GATED: no/invalid X-Nishi-Session -> 401). The textarea body is HTML-escaped. POST /wiki/<slug>/edit -> read the posted body (the new markdown), extract the session token, call nx_wiki_page_save. On OK -> 200 (saved + Refresh to the page); on REFUSED -> 401. Persisted nothing on refuse. SECURITY-CRITICAL: BOTH verbs gate on the SAME reused validator the core uses (hub/nx_modern_auth_flow::nx_modern_auth_validate_session). The GET form is itself behind the gate so the edit UI never renders for an anon visitor; the POST re-checks inside nx_wiki_page_save (defence in depth -- never trust the GET gate alone for the write). COMPOSES (each imported ONCE): wiki/nx_wiki_page_save nx_wiki_page_save + doc-store read helpers nx_http_header_find X-Nishi-Session extraction nx_base64 b64_decode (header carries base64(152B token)) html_escape textarea pre-fill escaping COMPOSED BY: wiki/nx_wiki_routes dispatch /wiki/<slug>/edit (GET + POST) Status: R1. 2026-06-14. license_tier: ORIGINAL

dependencies 5 imports · 3 importers

nx_syscalls.nx nx_wiki_page_save.nx nx_http_header_find.nx nx_base64.nx html_escape.nx nx_wiki_edit_handler.nx _wiki_edit_gate.nx _wiki_version_gate.nx nx_wiki_routes.nx

imports: nx_syscalls.nxnx_wiki_page_save.nxnx_http_header_find.nxnx_base64.nxhtml_escape.nx

imported by: _wiki_edit_gate.nx_wiki_version_gate.nxnx_wiki_routes.nx

structs

none

consts

36const NX_WEH_OK: i64 = 0
37const NX_WEH_BAD_INPUT: i64 = 2920
38const NX_WEH_OVERFLOW: i64 = 2921
41const NX_WEH_HDR_SESSION_NAME: *u8 = "X-Nishi-Session" as *u8
42const NX_WEH_HDR_SESSION_NAME_N: i64 = 15
43const NX_WEH_TOKEN_BYTES: i64 = 152
44const NX_WEH_MAX_SCAN: i64 = 16384
45const NX_WEH_MAX_BODY: i64 = 262144 // 256 KB posted markdown
46const NX_WEH_SUFFIX_EDIT: *u8 = "/edit" as *u8
47const NX_WEH_SUFFIX_EDIT_N: i64 = 5
48const NX_WEH_PREFIX_WIKI: *u8 = "/wiki/" as *u8
49const NX_WEH_PREFIX_WIKI_N: i64 = 6

functions

52func _weh_app(out: *u8, off: *i64, cap: i64, src: *u8, n: i64) -> i64
59func _weh_appz(out: *u8, off: *i64, cap: i64, z: *u8) -> i64
67func _weh_appn(out: *u8, off: *i64, cap: i64, v: i64) -> i64
81func nx_weh_slug_of(url_path: *u8, url_path_n: i64,
called by 1: nx_wiki_edit_handle
108func nx_weh_extract_token(http_req_buf: *u8, http_headers_end: i64,
131func nx_weh_content_length(http_req_buf: *u8, http_headers_end: i64) -> i64
154func nx_weh_emit_401(resp: *u8, cap: i64, out_n: *i64) -> i64
164func nx_weh_emit_404(resp: *u8, cap: i64, out_n: *i64) -> i64
175func nx_weh_emit_saved(resp: *u8, cap: i64, out_n: *i64,
203func nx_weh_emit_form(resp: *u8, cap: i64, out_n: *i64,
244func nx_weh_current_body(store: *NxWikiDocStore, slug: *u8, slug_n: i64,
272func nx_wiki_edit_handle(