nx_wiki_edit_handler.nx
buildroot/runtime/wiki/nx_wiki_edit_handler.nx
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
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
| 36 | const NX_WEH_OK: i64 = 0 |
| 37 | const NX_WEH_BAD_INPUT: i64 = 2920 |
| 38 | const NX_WEH_OVERFLOW: i64 = 2921 |
| 41 | const NX_WEH_HDR_SESSION_NAME: *u8 = "X-Nishi-Session" as *u8 |
| 42 | const NX_WEH_HDR_SESSION_NAME_N: i64 = 15 |
| 43 | const NX_WEH_TOKEN_BYTES: i64 = 152 |
| 44 | const NX_WEH_MAX_SCAN: i64 = 16384 |
| 45 | const NX_WEH_MAX_BODY: i64 = 262144 // 256 KB posted markdown |
| 46 | const NX_WEH_SUFFIX_EDIT: *u8 = "/edit" as *u8 |
| 47 | const NX_WEH_SUFFIX_EDIT_N: i64 = 5 |
| 48 | const NX_WEH_PREFIX_WIKI: *u8 = "/wiki/" as *u8 |
| 49 | const NX_WEH_PREFIX_WIKI_N: i64 = 6 |
functions
| 52 | func _weh_app(out: *u8, off: *i64, cap: i64, src: *u8, n: i64) -> i64 |
| 59 | func _weh_appz(out: *u8, off: *i64, cap: i64, z: *u8) -> i64 called by 5: nx_weh_emit_401nx_weh_emit_404nx_weh_emit_savednx_weh_emit_formnx_wiki_edit_handle calls 1: _weh_app |
| 67 | func _weh_appn(out: *u8, off: *i64, cap: i64, v: i64) -> i64 |
| 81 | func nx_weh_slug_of(url_path: *u8, url_path_n: i64, called by 1: nx_wiki_edit_handle |
| 108 | func nx_weh_extract_token(http_req_buf: *u8, http_headers_end: i64, |
| 131 | func nx_weh_content_length(http_req_buf: *u8, http_headers_end: i64) -> i64 |
| 154 | func nx_weh_emit_401(resp: *u8, cap: i64, out_n: *i64) -> i64 |
| 164 | func nx_weh_emit_404(resp: *u8, cap: i64, out_n: *i64) -> i64 |
| 175 | func nx_weh_emit_saved(resp: *u8, cap: i64, out_n: *i64, |
| 203 | func nx_weh_emit_form(resp: *u8, cap: i64, out_n: *i64, |
| 244 | func nx_weh_current_body(store: *NxWikiDocStore, slug: *u8, slug_n: i64, called by 1: nx_wiki_edit_handle calls 4: sys_mmapnx_wps_urlnx_wiki_doc_store_find_by_urlnx_wiki_doc_store_lookup |
| 272 | func nx_wiki_edit_handle( |