Skip to content

Commit

Permalink
fix: #9567, use regular 404
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed May 20, 2021
1 parent e6ef094 commit 5215c30
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions src/routes/feeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const helpers = require('../controllers/helpers');
const privileges = require('../privileges');
const db = require('../database');
const utils = require('../utils');
const controllers404 = require('../controllers/404.js');

const terms = {
daily: 'day',
Expand Down Expand Up @@ -60,9 +59,9 @@ async function validateTokenIfRequiresLogin(requiresLogin, cid, req, res) {
return true;
}

async function generateForTopic(req, res) {
async function generateForTopic(req, res, next) {
if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
return next();
}

const tid = req.params.topic_id;
Expand All @@ -73,7 +72,7 @@ async function generateForTopic(req, res) {
]);

if (!privileges.topics.canViewDeletedScheduled(topic, userPrivileges)) {
return controllers404.send404(req, res);
return next();
}

if (await validateTokenIfRequiresLogin(!userPrivileges['topics:read'], topic.cid, req, res)) {
Expand Down Expand Up @@ -116,11 +115,8 @@ async function generateForTopic(req, res) {
}

async function generateForCategory(req, res, next) {
if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
}
const cid = req.params.category_id;
if (!parseInt(cid, 10)) {
if (meta.config['feeds:disableRSS'] || !parseInt(cid, 10)) {
return next();
}

Expand Down Expand Up @@ -153,9 +149,9 @@ async function generateForCategory(req, res, next) {
}
}

async function generateForTopics(req, res) {
async function generateForTopics(req, res, next) {
if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
return next();
}
let token = null;
if (req.query.token && req.query.uid) {
Expand All @@ -171,9 +167,9 @@ async function generateForTopics(req, res) {
}, 'topics:tid', res);
}

async function generateForRecent(req, res) {
async function generateForRecent(req, res, next) {
if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
return next();
}
let token = null;
if (req.query.token && req.query.uid) {
Expand All @@ -189,9 +185,9 @@ async function generateForRecent(req, res) {
}, 'topics:recent', res);
}

async function generateForTop(req, res) {
async function generateForTop(req, res, next) {
if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
return next();
}
const term = terms[req.params.term] || 'day';

Expand Down Expand Up @@ -221,9 +217,9 @@ async function generateForTop(req, res) {
sendFeed(feed, res);
}

async function generateForPopular(req, res) {
async function generateForPopular(req, res, next) {
if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
return next();
}

const term = terms[req.params.term] || 'day';
Expand Down Expand Up @@ -309,9 +305,9 @@ async function generateTopicsFeed(feedOptions, feedTopics) {
return feed;
}

async function generateForRecentPosts(req, res) {
async function generateForRecentPosts(req, res, next) {
if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
return next();
}
const postData = await posts.getRecentPosts(req.uid, 0, 19, 'month');
const feed = generateForPostsFeed({
Expand All @@ -324,9 +320,9 @@ async function generateForRecentPosts(req, res) {
sendFeed(feed, res);
}

async function generateForCategoryRecentPosts(req, res) {
async function generateForCategoryRecentPosts(req, res, next) {
if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
return next();
}
const cid = req.params.category_id;

Expand All @@ -337,7 +333,7 @@ async function generateForCategoryRecentPosts(req, res) {
]);

if (!category) {
return controllers404.send404(req, res);
return next();
}

if (await validateTokenIfRequiresLogin(!userPrivileges.read, cid, req, res)) {
Expand Down Expand Up @@ -378,7 +374,7 @@ function generateForPostsFeed(feedOptions, posts) {

async function generateForUserTopics(req, res, next) {
if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
return next();
}

const { userslug } = req.params;
Expand All @@ -396,9 +392,9 @@ async function generateForUserTopics(req, res, next) {
}, `uid:${userData.uid}:topics`, res);
}

async function generateForTag(req, res) {
async function generateForTag(req, res, next) {
if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
return next();
}
const tag = validator.escape(String(req.params.tag));
const page = parseInt(req.query.page, 10) || 1;
Expand Down

0 comments on commit 5215c30

Please sign in to comment.