Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 5af65701 authored by echicken's avatar echicken 🐔

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

parent 28d330f9
......@@ -8,12 +8,13 @@ var settings = load('modopts.js', 'web') || { web_directory: '../webv4' };
load(settings.web_directory + '/lib/init.js');
load(settings.web_lib + 'auth.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 replied = false;
// 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;
......@@ -26,7 +27,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
// Unread message counts for every sub in a group
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]);
}
break;
......@@ -51,7 +52,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
break;
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]));
} else {
reply.success = false;
......@@ -59,7 +60,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
break;
case 'post':
if (Request.has_params(['sub', 'to', 'subject', 'body'])) {
if (request.has_params(['sub', 'to', 'subject', 'body'])) {
reply.success = postNew(
http_request.query.sub[0],
http_request.query.to[0],
......@@ -72,7 +73,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
break;
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]);
} else {
reply.success = false;
......@@ -80,7 +81,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
break;
case 'delete-mail':
if (Request.has_param('number')) {
if (request.has_param('number')) {
reply.success = deleteMail(http_request.query.number);
} else {
reply.success = false;
......@@ -88,7 +89,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
break;
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]);
} else {
reply.success = false;
......@@ -96,7 +97,7 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
break;
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]);
} else {
reply.success = false;
......@@ -104,13 +105,13 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
break;
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]);
}
break;
case 'submit-poll':
if (Request.has_params(['subject', 'sub', 'votes', 'results', 'answer'])) {
if (request.has_params(['subject', 'sub', 'votes', 'results', 'answer'])) {
reply.success = postPoll(
http_request.query.sub[0],
http_request.query.subject[0],
......@@ -144,26 +145,29 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
switch(http_request.query.call[0].toLowerCase()) {
case 'get-thread-votes':
if (Request.has_params(['sub', 'id'])) {
var id = parseInt(http_request.query.id[0]);
if (!isNaN(id)) reply = getVotesInThread(http_request.query.sub[0], id);
if (request.has_params(['sub', 'id'])) {
var id = parseInt(request.get_param('id'), 10);
if (!isNaN(id)) reply = getVotesInThread(request.get_param('sub'), id);
}
break;
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;
case 'get-poll-results':
if (Request.has_params(['sub', 'id'])) {
reply = getUserPollData(http_request.query.sub[0], http_request.query.id[0]);
if (request.has_params(['sub', 'id'])) {
reply = getUserPollData(request.get_param('sub'), request.get_param('id'));
}
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'));
if (request.has_params(['sub', 'thread'])) {
http_reply.header['Content-Type'] = 'text/plain; charset=utf8';
getThread(request.get_param('sub'), request.get_param('thread'), function (m) {
writeln(JSON.stringify(m));
});
replied = true;
}
break;
......@@ -172,18 +176,22 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
break;
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;
case 'list-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'));
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;
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;
default:
......@@ -195,15 +203,11 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
}
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
if (!replied) {
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
}
reply = undefined;
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment