postCount != lastPostIndex unfortunately, that will need some rethinking
This commit is contained in:
barisusakli
2014-06-26 22:11:16 -04:00
parent 49a9601a04
commit 1cabf885a2
5 changed files with 65 additions and 6 deletions

View File

@@ -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();