mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: add post queue to /compose POST route
This commit is contained in:
@@ -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([
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user