mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 10:46:14 +01:00
add /user/<uid> and /post/<pid> redirects
change notifications to use new redirects
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user