fixes to infinitescroll

This commit is contained in:
barisusakli
2014-06-02 20:41:03 -04:00
parent c342e75f6e
commit 0574022e02
14 changed files with 98 additions and 60 deletions

View File

@@ -79,6 +79,21 @@ middleware.addSlug = function(req, res, next) {
next();
};
middleware.checkPostIndex = function(req, res, next) {
topics.getPostCount(req.params.topic_id, function(err, postCount) {
if (err) {
return next(err);
}
var postIndex = parseInt(req.params.post_index, 10);
if (postIndex > postCount) {
return res.redirect('/topic/' + req.params.topic_id + '/' + req.params.slug + '/' + postCount);
} else if (postIndex <= 1) {
return res.redirect('/topic/' + req.params.topic_id + '/' + req.params.slug);
}
next();
});
};
middleware.prepareAPI = function(req, res, next) {
res.locals.isAPI = true;
next();