mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46: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) {
|
function (data, next) {
|
||||||
postData = data;
|
postData = data;
|
||||||
data.forEach(function (data) {
|
data.forEach(function (data) {
|
||||||
|
if (data) {
|
||||||
data.data = JSON.parse(data.data);
|
data.data = JSON.parse(data.data);
|
||||||
data.data.timestampISO = utils.toISOString(data.data.timestamp);
|
data.data.timestampISO = utils.toISOString(data.data.timestamp);
|
||||||
|
}
|
||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
const uids = data.map(data => data && data.uid);
|
const uids = data.map(data => data && data.uid);
|
||||||
@@ -73,10 +75,15 @@ function getQueuedPosts(ids, callback) {
|
|||||||
},
|
},
|
||||||
function (userData, next) {
|
function (userData, next) {
|
||||||
postData.forEach(function (postData, index) {
|
postData.forEach(function (postData, index) {
|
||||||
|
if (postData) {
|
||||||
postData.user = userData[index];
|
postData.user = userData[index];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
async.map(postData, function (postData, next) {
|
async.map(postData, function (postData, next) {
|
||||||
|
if (!postData) {
|
||||||
|
return next(null, postData);
|
||||||
|
}
|
||||||
postData.data.rawContent = validator.escape(String(postData.data.content));
|
postData.data.rawContent = validator.escape(String(postData.data.content));
|
||||||
postData.data.title = validator.escape(String(postData.data.title || ''));
|
postData.data.title = validator.escape(String(postData.data.title || ''));
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ var nconf = require('nconf');
|
|||||||
var user = require('../user');
|
var user = require('../user');
|
||||||
var plugins = require('../plugins');
|
var plugins = require('../plugins');
|
||||||
var topics = require('../topics');
|
var topics = require('../topics');
|
||||||
|
var posts = require('../posts');
|
||||||
var helpers = require('./helpers');
|
var helpers = require('./helpers');
|
||||||
|
|
||||||
exports.get = function (req, res, callback) {
|
exports.get = function (req, res, callback) {
|
||||||
@@ -53,21 +54,38 @@ exports.post = function (req, res) {
|
|||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
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) {
|
if (body.tid) {
|
||||||
data.tid = body.tid;
|
data.tid = body.tid;
|
||||||
topics.reply(data, next);
|
queueOrPost(topics.reply, data, next);
|
||||||
} else if (body.cid) {
|
} else if (body.cid) {
|
||||||
data.cid = body.cid;
|
data.cid = body.cid;
|
||||||
data.title = body.title;
|
data.title = body.title;
|
||||||
data.tags = [];
|
data.tags = [];
|
||||||
data.thumb = '';
|
data.thumb = '';
|
||||||
|
queueOrPost(topics.post, data, next);
|
||||||
topics.post(data, next);
|
|
||||||
} else {
|
} else {
|
||||||
next(new Error('[[error:invalid-data]]'));
|
next(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
function (result, next) {
|
function (result, next) {
|
||||||
|
if (result.queued) {
|
||||||
|
return res.redirect((nconf.get('relative_path') || '/'));
|
||||||
|
}
|
||||||
var uid = result.uid ? result.uid : result.topicData.uid;
|
var uid = result.uid ? result.uid : result.topicData.uid;
|
||||||
user.updateOnlineUsers(uid);
|
user.updateOnlineUsers(uid);
|
||||||
next(null, result.pid ? '/post/' + result.pid : '/topic/' + result.topicData.slug);
|
next(null, result.pid ? '/post/' + result.pid : '/topic/' + result.topicData.slug);
|
||||||
|
|||||||
Reference in New Issue
Block a user