mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 15:05:46 +01:00
closes #1730
postCount != lastPostIndex unfortunately, that will need some rethinking
This commit is contained in:
@@ -99,6 +99,26 @@ middleware.checkPostIndex = function(req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
middleware.checkTopicIndex = function(req, res, next) {
|
||||
categories.getCategoryField(req.params.category_id, 'topic_count', function(err, topicCount) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
var topicIndex = parseInt(req.params.topic_index, 10);
|
||||
topicCount = parseInt(topicCount, 10) + 1;
|
||||
var url = '';
|
||||
console.log(topicIndex, topicCount);
|
||||
if (topicIndex > topicCount) {
|
||||
url = '/category/' + req.params.category_id + '/' + req.params.slug + '/' + topicCount;
|
||||
return res.locals.isAPI ? res.json(302, url) : res.redirect(url);
|
||||
} else if (topicIndex < 1) {
|
||||
url = '/category/' + req.params.category_id + '/' + req.params.slug;
|
||||
return res.locals.isAPI ? res.json(302, url) : res.redirect(url);
|
||||
}
|
||||
next();
|
||||
});
|
||||
};
|
||||
|
||||
middleware.prepareAPI = function(req, res, next) {
|
||||
res.locals.isAPI = true;
|
||||
next();
|
||||
|
||||
Reference in New Issue
Block a user