add /user/<uid> and /post/<pid> redirects

change notifications to use new redirects
This commit is contained in:
barisusakli
2016-05-05 20:24:03 +03:00
parent b0747ad10e
commit eb0aea6390
15 changed files with 142 additions and 156 deletions

View File

@@ -1,8 +1,10 @@
'use strict';
var async = require('async'),
topics = require('../topics');
var async = require('async');
var topics = require('../topics');
var utils = require('../../public/src/utils');
module.exports = function(Posts) {
@@ -42,4 +44,49 @@ module.exports = function(Posts) {
], callback);
};
Posts.generatePostPath = function (pid, uid, callback) {
Posts.generatePostPaths([pid], uid, function(err, paths) {
callback(err, Array.isArray(paths) && paths.length ? paths[0] : null);
});
};
Posts.generatePostPaths = function (pids, uid, callback) {
async.waterfall([
function (next) {
Posts.getPostsFields(pids, ['pid', 'tid'], next);
},
function (postData, next) {
async.parallel({
indices: function(next) {
Posts.getPostIndices(postData, uid, next);
},
topics: function(next) {
var tids = postData.map(function(post) {
return post ? post.tid : null;
});
topics.getTopicsFields(tids, ['slug', 'deleted'], next);
}
}, next);
},
function (results, next) {
var paths = pids.map(function(pid, index) {
if (parseInt(results.topics[index].deleted, 10) === 1) {
return null;
}
var slug = results.topics[index] ? results.topics[index].slug : null;
var postIndex = utils.isNumber(results.indices[index]) ? parseInt(results.indices[index], 10) + 1 : null;
if (slug && postIndex) {
return '/topic/' + slug + '/' + postIndex;
}
return null;
});
next(null, paths);
}
], callback);
};
};