mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-05 22:58:35 +02:00
Merge branch 'master' of https://github.com/NodeBB/NodeBB
This commit is contained in:
@@ -20,7 +20,7 @@ topicsController.get = function(req, res, next) {
|
||||
userPrivileges;
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
function (next) {
|
||||
privileges.topics.get(tid, uid, function(err, privileges) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -40,8 +40,16 @@ topicsController.get = function(req, res, next) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var start = (page - 1) * settings.postsPerPage,
|
||||
end = start + settings.postsPerPage - 1;
|
||||
var postIndex = 0;
|
||||
if (!settings.usePagination) {
|
||||
postIndex = Math.max((req.params.post_index || 1) - (settings.postsPerPage), 0);
|
||||
} else if (!req.query.page) {
|
||||
var index = Math.max(parseInt((req.params.post_index || 0), 10), 0);
|
||||
page = Math.ceil((index + 1) / settings.postsPerPage);
|
||||
}
|
||||
|
||||
var start = (page - 1) * settings.postsPerPage + postIndex,
|
||||
end = start + settings.postsPerPage - 1 + postIndex;
|
||||
|
||||
topics.getTopicWithPosts(tid, uid, start, end, function (err, topicData) {
|
||||
if (topicData) {
|
||||
|
||||
@@ -274,6 +274,9 @@ var db = require('./database'),
|
||||
}
|
||||
|
||||
postTools.parse(post.content, next);
|
||||
},
|
||||
index: function(next) {
|
||||
Posts.getPidIndex(post.pid, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
@@ -283,6 +286,7 @@ var db = require('./database'),
|
||||
post.user = results.user;
|
||||
post.topic = results.topicCategory.topic;
|
||||
post.category = results.topicCategory.category;
|
||||
post.index = parseInt(results.index, 10) + 1;
|
||||
|
||||
if (stripTags) {
|
||||
var s = S(results.content);
|
||||
|
||||
@@ -51,6 +51,9 @@ function staticRoutes(app, middleware, controllers) {
|
||||
function topicRoutes(app, middleware, controllers) {
|
||||
app.get('/api/topic/teaser/:topic_id', controllers.topics.teaser);
|
||||
|
||||
app.get('/topic/:topic_id/:slug/:post_index?', middleware.buildHeader, middleware.addSlug, controllers.topics.get);
|
||||
app.get('/api/topic/:topic_id/:slug/:post_index?', controllers.topics.get);
|
||||
|
||||
app.get('/topic/:topic_id/:slug?', middleware.buildHeader, middleware.addSlug, controllers.topics.get);
|
||||
app.get('/api/topic/:topic_id/:slug?', controllers.topics.get);
|
||||
}
|
||||
|
||||
@@ -312,29 +312,40 @@ var async = require('async'),
|
||||
|
||||
Topics.getTeaser = function(tid, callback) {
|
||||
Topics.getLatestUndeletedPid(tid, function(err, pid) {
|
||||
if (err) {
|
||||
if (err || !pid) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!pid) {
|
||||
return callback(null, null);
|
||||
}
|
||||
async.parallel({
|
||||
postData: function(next) {
|
||||
posts.getPostFields(pid, ['pid', 'uid', 'timestamp'], function(err, postData) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
} else if(!postData || !utils.isNumber(postData.uid)) {
|
||||
return next(new Error('[[error:no-teaser]]'));
|
||||
}
|
||||
|
||||
posts.getPostFields(pid, ['pid', 'uid', 'timestamp'], function(err, postData) {
|
||||
user.getUserFields(postData.uid, ['username', 'userslug', 'picture'], function(err, userData) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
postData.user = userData;
|
||||
next(null, postData);
|
||||
});
|
||||
});
|
||||
},
|
||||
postIndex: function(next) {
|
||||
posts.getPidIndex(pid, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
} else if(!postData || !utils.isNumber(postData.uid)) {
|
||||
return callback(new Error('[[error:no-teaser]]'));
|
||||
}
|
||||
|
||||
user.getUserFields(postData.uid, ['username', 'userslug', 'picture'], function(err, userData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
postData.timestamp = utils.toISOString(postData.timestamp);
|
||||
postData.user = userData;
|
||||
callback(null, postData);
|
||||
});
|
||||
results.postData.timestamp = utils.toISOString(results.postData.timestamp);
|
||||
results.postData.index = parseInt(results.postIndex, 10) + 1;
|
||||
|
||||
callback(null, results.postData);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -24,9 +24,15 @@ module.exports = function(Topics) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var slug = tid + '/' + utils.slugify(title),
|
||||
var slug = utils.slugify(title),
|
||||
timestamp = Date.now();
|
||||
|
||||
if (!slug.length) {
|
||||
return callback(new Error('[[error:invalid-title]]'));
|
||||
}
|
||||
|
||||
slug = tid + '/' + slug;
|
||||
|
||||
var topicData = {
|
||||
'tid': tid,
|
||||
'uid': uid,
|
||||
|
||||
@@ -29,7 +29,7 @@ module.exports = function(Topics) {
|
||||
if (Array.isArray(postData) && !postData.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
start = parseInt(start, 10);
|
||||
for(var i=0; i<postData.length; ++i) {
|
||||
postData[i].index = start + i;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user