Skip to content
Snippets Groups Projects
Commit 5af65701 authored by echicken's avatar echicken :chicken:
Browse files

Use require() and request; some WIP stuff for the new forum that will change later.

parent 28d330f9
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
...@@ -8,12 +8,13 @@ var settings = load('modopts.js', 'web') || { web_directory: '../webv4' }; ...@@ -8,12 +8,13 @@ var settings = load('modopts.js', 'web') || { web_directory: '../webv4' };
load(settings.web_directory + '/lib/init.js'); load(settings.web_directory + '/lib/init.js');
load(settings.web_lib + 'auth.js'); load(settings.web_lib + 'auth.js');
load(settings.web_lib + 'forum.js'); load(settings.web_lib + 'forum.js');
load(settings.web_lib + 'request.js'); var request = require({}, settings.web_lib + 'request.js', 'request');
var reply = {}; var reply = {};
var replied = false;
// There must be an API call, and the user must not be a guest or unknown // There must be an API call, and the user must not be a guest or unknown
if (Request.has_param('call') && (http_request.method === 'GET' || http_request.method === 'POST')) { if (request.has_param('call') && (http_request.method === 'GET' || http_request.method === 'POST')) {
var handled = false; var handled = false;
...@@ -26,7 +27,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request. ...@@ -26,7 +27,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
// Unread message counts for every sub in a group // Unread message counts for every sub in a group
case 'get-sub-unread-counts': case 'get-sub-unread-counts':
if (Request.has_param('group') && msg_area.grp_list[http_request.query.group[0]]) { if (request.has_param('group') && msg_area.grp_list[http_request.query.group[0]]) {
reply = getSubUnreadCounts(http_request.query.group[0]); reply = getSubUnreadCounts(http_request.query.group[0]);
} }
break; break;
...@@ -51,7 +52,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request. ...@@ -51,7 +52,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
break; break;
case 'post-reply': case 'post-reply':
if (Request.has_params(['sub', 'body', 'pid'])) { if (request.has_params(['sub', 'body', 'pid'])) {
reply.success = postReply(http_request.query.sub[0], http_request.query.body[0], Number(http_request.query.pid[0])); reply.success = postReply(http_request.query.sub[0], http_request.query.body[0], Number(http_request.query.pid[0]));
} else { } else {
reply.success = false; reply.success = false;
...@@ -59,7 +60,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request. ...@@ -59,7 +60,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
break; break;
case 'post': case 'post':
if (Request.has_params(['sub', 'to', 'subject', 'body'])) { if (request.has_params(['sub', 'to', 'subject', 'body'])) {
reply.success = postNew( reply.success = postNew(
http_request.query.sub[0], http_request.query.sub[0],
http_request.query.to[0], http_request.query.to[0],
...@@ -72,7 +73,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request. ...@@ -72,7 +73,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
break; break;
case 'delete-message': case 'delete-message':
if (Request.has_params(['sub', 'number'])) { if (request.has_params(['sub', 'number'])) {
reply.success = deleteMessage(http_request.query.sub[0], http_request.query.number[0]); reply.success = deleteMessage(http_request.query.sub[0], http_request.query.number[0]);
} else { } else {
reply.success = false; reply.success = false;
...@@ -80,7 +81,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request. ...@@ -80,7 +81,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
break; break;
case 'delete-mail': case 'delete-mail':
if (Request.has_param('number')) { if (request.has_param('number')) {
reply.success = deleteMail(http_request.query.number); reply.success = deleteMail(http_request.query.number);
} else { } else {
reply.success = false; reply.success = false;
...@@ -88,7 +89,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request. ...@@ -88,7 +89,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
break; break;
case 'set-scan-cfg': case 'set-scan-cfg':
if (Request.has_params(['sub', 'cfg'])) { if (request.has_params(['sub', 'cfg'])) {
reply.success = setScanCfg(http_request.query.sub[0], http_request.query.cfg[0]); reply.success = setScanCfg(http_request.query.sub[0], http_request.query.cfg[0]);
} else { } else {
reply.success = false; reply.success = false;
...@@ -96,7 +97,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request. ...@@ -96,7 +97,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
break; break;
case 'vote': case 'vote':
if (Request.has_params(['sub', 'id', 'up']) && !(user.security.restrictions&UFLAG_V)) { if (request.has_params(['sub', 'id', 'up']) && !(user.security.restrictions&UFLAG_V)) {
reply.success = voteMessage(http_request.query.sub[0], http_request.query.id[0], http_request.query.up[0]); reply.success = voteMessage(http_request.query.sub[0], http_request.query.id[0], http_request.query.up[0]);
} else { } else {
reply.success = false; reply.success = false;
...@@ -104,13 +105,13 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request. ...@@ -104,13 +105,13 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
break; break;
case 'submit-poll-answers': case 'submit-poll-answers':
if (Request.has_params(['sub', 'id', 'answer'])) { if (request.has_params(['sub', 'id', 'answer'])) {
reply.success = submitPollAnswers(http_request.query.sub[0], http_request.query.id[0], http_request.query.answer[0]); reply.success = submitPollAnswers(http_request.query.sub[0], http_request.query.id[0], http_request.query.answer[0]);
} }
break; break;
case 'submit-poll': case 'submit-poll':
if (Request.has_params(['subject', 'sub', 'votes', 'results', 'answer'])) { if (request.has_params(['subject', 'sub', 'votes', 'results', 'answer'])) {
reply.success = postPoll( reply.success = postPoll(
http_request.query.sub[0], http_request.query.sub[0],
http_request.query.subject[0], http_request.query.subject[0],
...@@ -144,26 +145,29 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request. ...@@ -144,26 +145,29 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
switch(http_request.query.call[0].toLowerCase()) { switch(http_request.query.call[0].toLowerCase()) {
case 'get-thread-votes': case 'get-thread-votes':
if (Request.has_params(['sub', 'id'])) { if (request.has_params(['sub', 'id'])) {
var id = parseInt(http_request.query.id[0]); var id = parseInt(request.get_param('id'), 10);
if (!isNaN(id)) reply = getVotesInThread(http_request.query.sub[0], id); if (!isNaN(id)) reply = getVotesInThread(request.get_param('sub'), id);
} }
break; break;
case 'get-sub-votes': case 'get-sub-votes':
if (Request.has_param('sub')) reply = getVotesInThreads(http_request.query.sub[0]); if (request.has_param('sub')) reply = getVotesInThreads(request.get_param('sub'));
break; break;
case 'get-poll-results': case 'get-poll-results':
if (Request.has_params(['sub', 'id'])) { if (request.has_params(['sub', 'id'])) {
reply = getUserPollData(http_request.query.sub[0], http_request.query.id[0]); reply = getUserPollData(request.get_param('sub'), request.get_param('id'));
} }
break; break;
case 'get-thread': case 'get-thread':
if (Request.has_params(['sub', 'thread'])) { if (request.has_params(['sub', 'thread'])) {
if (Request.has_param('count')) var count = Request.get_param('count'); http_reply.header['Content-Type'] = 'text/plain; charset=utf8';
reply = getMessageThread(Request.get_param('sub'), Request.get_param('thread'), count || settings.page_size, Request.get_param('after')); getThread(request.get_param('sub'), request.get_param('thread'), function (m) {
writeln(JSON.stringify(m));
});
replied = true;
} }
break; break;
...@@ -172,18 +176,22 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request. ...@@ -172,18 +176,22 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
break; break;
case 'list-subs': case 'list-subs':
if (Request.has_param('group')) reply = listSubs(http_request.query.group[0]); if (request.has_param('group')) reply = listSubs(request.get_param('group'));
break; break;
case 'list-threads': case 'list-threads':
if (Request.has_param('sub')) { if (request.has_param('sub')) {
if (Request.has_param('count')) var count = Request.get_param(count); 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')); reply = listThreads(request.get_param('sub'), count || settings.page_size, request.get_param('after'));
} }
break; break;
case 'get-newest-message-per-sub': case 'get-newest-message-per-sub':
if (Request.has_param('group')) reply = getNewestMessagePerSub(Request.get_param('group')); if (request.has_param('group')) reply = getNewestMessagePerSub(request.get_param('group'));
break;
case 'get-thread-list':
if (request.has_param('sub')) reply = getThreadList(request.get_param('sub'));
break; break;
default: default:
...@@ -195,15 +203,11 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request. ...@@ -195,15 +203,11 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
} }
if (typeof reply === 'function') { // generator if (!replied) {
var r;
http_reply.header['Content-Type'] = 'application/json';
while ((r = reply()) !== null) {
writeln(JSON.stringify(r));
}
} else { // Normal reply
reply = JSON.stringify(reply); reply = JSON.stringify(reply);
http_reply.header['Content-Type'] = 'application/json'; http_reply.header['Content-Type'] = 'application/json';
http_reply.header['Content-Length'] = reply.length; http_reply.header['Content-Length'] = reply.length;
write(reply); write(reply);
} }
\ No newline at end of file
reply = undefined;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment