From ff4f0cd2247aa0037d0841d0b56f8952bf6ff767 Mon Sep 17 00:00:00 2001 From: echicken <echicken@bbs.electronicchicken.com> Date: Fri, 26 Feb 2021 14:17:32 -0500 Subject: [PATCH] Added get-thread call, support for generatorish reply value. list-threads doesn't need offset, instead will begin at the message after 'after' if given. --- webv4/root/api/forum.ssjs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/webv4/root/api/forum.ssjs b/webv4/root/api/forum.ssjs index 5eb01d9364..18e4f4a188 100644 --- a/webv4/root/api/forum.ssjs +++ b/webv4/root/api/forum.ssjs @@ -160,6 +160,13 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request. } break; + case 'get-thread': + if (Request.has_params(['sub', 'thread'])) { + if (Request.has_param('count')) var count = Request.get_param('count'); + reply = getMessageThread(Request.get_param('sub'), Request.get_param('thread'), count || settings.page_size, Request.get_param('after')); + } + break; + case 'list-groups': reply = listGroups(); break; @@ -169,9 +176,9 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request. break; case 'list-threads': - if (Request.has_params(['sub', 'offset'])) { - if (Request.has_param('count')) var count = http_request.query.count[0]; - reply = listThreads(http_request.query.sub[0], http_request.query.offset[0], count || settings.page_size).threads; + if (Request.has_param('sub')) { + if (Request.has_param('count')) var count = Request.get_param(count); + reply = listThreads(Request.get_param('sub'), count || settings.page_size, Request.get_param('after')); } break; @@ -188,7 +195,15 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request. } -reply = JSON.stringify(reply); -http_reply.header['Content-Type'] = 'application/json'; -http_reply.header['Content-Length'] = reply.length; -write(reply); +if (typeof reply === 'function') { // generator + var r; + http_reply.header['Content-Type'] = 'application/json'; + while ((r = reply()) !== null) { + writeln(JSON.stringify(r)); + } +} else { // Normal reply + reply = JSON.stringify(reply); + http_reply.header['Content-Type'] = 'application/json'; + http_reply.header['Content-Length'] = reply.length; + write(reply); +} \ No newline at end of file -- GitLab