Node.js based forum software built for the modern web
fix: add post queue to /compose POST route
Barış Soner Uşaklıc6cd6c5705a2
diff --git a/src/controllers/admin/postqueue.js b/src/controllers/admin/postqueue.jsindex 52754637a6..1cb66ff0c8 100644--- a/src/controllers/admin/postqueue.js+++ b/src/controllers/admin/postqueue.js@@ -64,8 +64,10 @@ function getQueuedPosts(ids, callback) {function (data, next) {postData = data;data.forEach(function (data) {- data.data = JSON.parse(data.data);- data.data.timestampISO = utils.toISOString(data.data.timestamp);+ if (data) {+ data.data = JSON.parse(data.data);+ data.data.timestampISO = utils.toISOString(data.data.timestamp);+ }return data;});const uids = data.map(data => data && data.uid);@@ -73,10 +75,15 @@ function getQueuedPosts(ids, callback) {},function (userData, next) {postData.forEach(function (postData, index) {- postData.user = userData[index];+ if (postData) {+ postData.user = userData[index];+ }});async.map(postData, function (postData, next) {+ if (!postData) {+ return next(null, postData);+ }postData.data.rawContent = validator.escape(String(postData.data.content));postData.data.title = validator.escape(String(postData.data.title || ''));async.waterfall([diff --git a/src/controllers/composer.js b/src/controllers/composer.jsindex 880e1b2b78..356cae1f57 100644--- a/src/controllers/composer.js+++ b/src/controllers/composer.js@@ -6,6 +6,7 @@ var nconf = require('nconf');var user = require('../user');var plugins = require('../plugins');var topics = require('../topics');+var posts = require('../posts');var helpers = require('./helpers');exports.get = function (req, res, callback) {@@ -53,21 +54,38 @@ exports.post = function (req, res) {async.waterfall([function (next) {+ function queueOrPost(postFn, data, next) {+ async.waterfall([+ function (next) {+ posts.shouldQueue(req.uid, data, next);+ },+ function (shouldQueue, next) {+ if (shouldQueue) {+ delete data.req;+ posts.addToQueue(data, next);+ } else {+ postFn(data, next);+ }+ },+ ], next);+ }if (body.tid) {data.tid = body.tid;- topics.reply(data, next);+ queueOrPost(topics.reply, data, next);} else if (body.cid) {data.cid = body.cid;data.title = body.title;data.tags = [];data.thumb = '';-- topics.post(data, next);+ queueOrPost(topics.post, data, next);} else {next(new Error('[[error:invalid-data]]'));}},function (result, next) {+ if (result.queued) {+ return res.redirect((nconf.get('relative_path') || '/'));+ }var uid = result.uid ? result.uid : result.topicData.uid;user.updateOnlineUsers(uid);next(null, result.pid ? '/post/' + result.pid : '/topic/' + result.topicData.slug);