|
|
|
@ -26,7 +26,7 @@ module.exports = function (app, middleware) {
|
|
|
|
|
app.get('/tags/:tag.rss', middleware.maintenanceMode, generateForTag);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function validateTokenIfRequiresLogin(requiresLogin, req, res, callback) {
|
|
|
|
|
function validateTokenIfRequiresLogin(requiresLogin, cid, req, res, callback) {
|
|
|
|
|
var uid = req.query.uid;
|
|
|
|
|
var token = req.query.token;
|
|
|
|
|
|
|
|
|
@ -38,23 +38,31 @@ function validateTokenIfRequiresLogin(requiresLogin, req, res, callback) {
|
|
|
|
|
return helpers.notAllowed(req, res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
user.getUserField(uid, 'rss_token', function (err, _token) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (token === _token) {
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
user.auth.logAttempt(uid, req.ip, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
user.getUserField(uid, 'rss_token', next);
|
|
|
|
|
},
|
|
|
|
|
function (_token, next) {
|
|
|
|
|
if (token === _token) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
privileges.categories.get(cid, uid, next);
|
|
|
|
|
},
|
|
|
|
|
function (privileges, next) {
|
|
|
|
|
if (!privileges.read) {
|
|
|
|
|
return helpers.notAllowed(req, res);
|
|
|
|
|
}
|
|
|
|
|
next();
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return helpers.notAllowed(req, res);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
user.auth.logAttempt(uid, req.ip, next);
|
|
|
|
|
},
|
|
|
|
|
function () {
|
|
|
|
|
helpers.notAllowed(req, res);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function generateForTopic(req, res, callback) {
|
|
|
|
@ -64,6 +72,7 @@ function generateForTopic(req, res, callback) {
|
|
|
|
|
|
|
|
|
|
var tid = req.params.topic_id;
|
|
|
|
|
var userPrivileges;
|
|
|
|
|
var topic;
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
@ -79,15 +88,12 @@ function generateForTopic(req, res, callback) {
|
|
|
|
|
if (!results.topic || (parseInt(results.topic.deleted, 10) && !results.privileges.view_deleted)) {
|
|
|
|
|
return controllers404.send404(req, res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
validateTokenIfRequiresLogin(!results.privileges['topics:read'], req, res, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userPrivileges = results.privileges;
|
|
|
|
|
topics.getTopicWithPosts(results.topic, 'tid:' + tid + ':posts', req.uid, 0, 25, false, next);
|
|
|
|
|
});
|
|
|
|
|
userPrivileges = results.privileges;
|
|
|
|
|
topic = results.topic;
|
|
|
|
|
validateTokenIfRequiresLogin(!results.privileges['topics:read'], results.topic.cid, req, res, next);
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
|
topics.getTopicWithPosts(topic, 'tid:' + tid + ':posts', req.uid || req.query.uid || 0, 0, 25, false, next);
|
|
|
|
|
},
|
|
|
|
|
function (topicData) {
|
|
|
|
|
topics.modifyPostsByPrivilege(topicData, userPrivileges);
|
|
|
|
@ -130,40 +136,12 @@ function generateForTopic(req, res, callback) {
|
|
|
|
|
], callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function generateForUserTopics(req, res, callback) {
|
|
|
|
|
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
|
|
|
|
return controllers404.send404(req, res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userslug = req.params.userslug;
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
user.getUidByUserslug(userslug, next);
|
|
|
|
|
},
|
|
|
|
|
function (uid, next) {
|
|
|
|
|
if (!uid) {
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
user.getUserFields(uid, ['uid', 'username'], next);
|
|
|
|
|
},
|
|
|
|
|
function (userData, next) {
|
|
|
|
|
generateForTopics({
|
|
|
|
|
uid: req.uid,
|
|
|
|
|
title: 'Topics by ' + userData.username,
|
|
|
|
|
description: 'A list of topics that are posted by ' + userData.username,
|
|
|
|
|
feed_url: '/user/' + userslug + '/topics.rss',
|
|
|
|
|
site_url: '/user/' + userslug + '/topics',
|
|
|
|
|
}, 'uid:' + userData.uid + ':topics', req, res, next);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function generateForCategory(req, res, next) {
|
|
|
|
|
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
|
|
|
|
return controllers404.send404(req, res);
|
|
|
|
|
}
|
|
|
|
|
var cid = req.params.category_id;
|
|
|
|
|
var category;
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
@ -178,25 +156,23 @@ function generateForCategory(req, res, next) {
|
|
|
|
|
reverse: true,
|
|
|
|
|
start: 0,
|
|
|
|
|
stop: 25,
|
|
|
|
|
uid: req.uid,
|
|
|
|
|
uid: req.uid || req.query.uid || 0,
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
validateTokenIfRequiresLogin(!results.privileges.read, req, res, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
generateTopicsFeed({
|
|
|
|
|
uid: req.uid,
|
|
|
|
|
title: results.category.name,
|
|
|
|
|
description: results.category.description,
|
|
|
|
|
feed_url: '/category/' + cid + '.rss',
|
|
|
|
|
site_url: '/category/' + results.category.cid,
|
|
|
|
|
}, results.category.topics, next);
|
|
|
|
|
});
|
|
|
|
|
category = results.category;
|
|
|
|
|
validateTokenIfRequiresLogin(!results.privileges.read, cid, req, res, next);
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
|
generateTopicsFeed({
|
|
|
|
|
uid: req.uid || req.query.uid || 0,
|
|
|
|
|
title: category.name,
|
|
|
|
|
description: category.description,
|
|
|
|
|
feed_url: '/category/' + cid + '.rss',
|
|
|
|
|
site_url: '/category/' + category.cid,
|
|
|
|
|
}, category.topics, next);
|
|
|
|
|
},
|
|
|
|
|
function (feed) {
|
|
|
|
|
sendFeed(feed, res);
|
|
|
|
@ -330,12 +306,13 @@ function generateForRecentPosts(req, res, next) {
|
|
|
|
|
], next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function generateForCategoryRecentPosts(req, res, next) {
|
|
|
|
|
function generateForCategoryRecentPosts(req, res, callback) {
|
|
|
|
|
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
|
|
|
|
return controllers404.send404(req, res);
|
|
|
|
|
}
|
|
|
|
|
var cid = req.params.category_id;
|
|
|
|
|
|
|
|
|
|
var category;
|
|
|
|
|
var posts;
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
@ -346,31 +323,29 @@ function generateForCategoryRecentPosts(req, res, next) {
|
|
|
|
|
categories.getCategoryData(cid, next);
|
|
|
|
|
},
|
|
|
|
|
posts: function (next) {
|
|
|
|
|
categories.getRecentReplies(cid, req.uid, 20, next);
|
|
|
|
|
categories.getRecentReplies(cid, req.uid || req.query.uid || 0, 20, next);
|
|
|
|
|
},
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
if (!results.category) {
|
|
|
|
|
return next();
|
|
|
|
|
return controllers404.send404(req, res);
|
|
|
|
|
}
|
|
|
|
|
category = results.category;
|
|
|
|
|
posts = results.posts;
|
|
|
|
|
validateTokenIfRequiresLogin(!results.privileges.read, cid, req, res, next);
|
|
|
|
|
},
|
|
|
|
|
function () {
|
|
|
|
|
var feed = generateForPostsFeed({
|
|
|
|
|
title: category.name + ' Recent Posts',
|
|
|
|
|
description: 'A list of recent posts from ' + category.name,
|
|
|
|
|
feed_url: '/category/' + cid + '/recentposts.rss',
|
|
|
|
|
site_url: '/category/' + cid + '/recentposts',
|
|
|
|
|
}, posts);
|
|
|
|
|
|
|
|
|
|
validateTokenIfRequiresLogin(!results.privileges.read, req, res, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var feed = generateForPostsFeed({
|
|
|
|
|
title: results.category.name + ' Recent Posts',
|
|
|
|
|
description: 'A list of recent posts from ' + results.category.name,
|
|
|
|
|
feed_url: '/category/' + cid + '/recentposts.rss',
|
|
|
|
|
site_url: '/category/' + cid + '/recentposts',
|
|
|
|
|
}, results.posts);
|
|
|
|
|
|
|
|
|
|
sendFeed(feed, res);
|
|
|
|
|
});
|
|
|
|
|
sendFeed(feed, res);
|
|
|
|
|
},
|
|
|
|
|
], next);
|
|
|
|
|
], callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function generateForPostsFeed(feedOptions, posts) {
|
|
|
|
@ -397,6 +372,35 @@ function generateForPostsFeed(feedOptions, posts) {
|
|
|
|
|
return feed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function generateForUserTopics(req, res, callback) {
|
|
|
|
|
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
|
|
|
|
return controllers404.send404(req, res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userslug = req.params.userslug;
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
user.getUidByUserslug(userslug, next);
|
|
|
|
|
},
|
|
|
|
|
function (uid, next) {
|
|
|
|
|
if (!uid) {
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
user.getUserFields(uid, ['uid', 'username'], next);
|
|
|
|
|
},
|
|
|
|
|
function (userData, next) {
|
|
|
|
|
generateForTopics({
|
|
|
|
|
uid: req.uid,
|
|
|
|
|
title: 'Topics by ' + userData.username,
|
|
|
|
|
description: 'A list of topics that are posted by ' + userData.username,
|
|
|
|
|
feed_url: '/user/' + userslug + '/topics.rss',
|
|
|
|
|
site_url: '/user/' + userslug + '/topics',
|
|
|
|
|
}, 'uid:' + userData.uid + ':topics', req, res, next);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function generateForTag(req, res, next) {
|
|
|
|
|
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
|
|
|
|
return controllers404.send404(req, res);
|
|
|
|
|