mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-14 10:37:45 +01:00
fix: #10682, fix all the other rss routes as well
This commit is contained in:
@@ -310,7 +310,7 @@ const utils = {
|
|||||||
|
|
||||||
tag = tag.trim().toLowerCase();
|
tag = tag.trim().toLowerCase();
|
||||||
// see https://github.com/NodeBB/NodeBB/issues/4378
|
// see https://github.com/NodeBB/NodeBB/issues/4378
|
||||||
tag = tag.replace(/\u202E/gi, '');
|
tag = utils.stripBidiControls(tag);
|
||||||
tag = tag.replace(/[,/#!$^*;:{}=_`<>'"~()?|]/g, '');
|
tag = tag.replace(/[,/#!$^*;:{}=_`<>'"~()?|]/g, '');
|
||||||
tag = tag.slice(0, maxLength || 15).trim();
|
tag = tag.slice(0, maxLength || 15).trim();
|
||||||
const matches = tag.match(/^[.-]*(.+?)[.-]*$/);
|
const matches = tag.match(/^[.-]*(.+?)[.-]*$/);
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ async function generateTopicsFeed(feedOptions, feedTopics, timestampField) {
|
|||||||
feedOptions.feed_url = nconf.get('url') + feedOptions.feed_url;
|
feedOptions.feed_url = nconf.get('url') + feedOptions.feed_url;
|
||||||
feedOptions.site_url = nconf.get('url') + feedOptions.site_url;
|
feedOptions.site_url = nconf.get('url') + feedOptions.site_url;
|
||||||
|
|
||||||
feedTopics = feedTopics.filter(Boolean);
|
feedTopics = feedTopics.filter(t => t && !t.deleted);
|
||||||
|
|
||||||
const feed = new rss(feedOptions);
|
const feed = new rss(feedOptions);
|
||||||
|
|
||||||
@@ -271,38 +271,39 @@ async function generateTopicsFeed(feedOptions, feedTopics, timestampField) {
|
|||||||
feed.pubDate = new Date(feedTopics[0][timestampField]).toUTCString();
|
feed.pubDate = new Date(feedTopics[0][timestampField]).toUTCString();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addFeedItem(topicData) {
|
if (feedOptions.useMainPost) {
|
||||||
|
const tids = feedTopics.map(topic => topic.tid);
|
||||||
|
const mainPosts = await topics.getMainPosts(tids, feedOptions.uid);
|
||||||
|
feedTopics.forEach((topicData, index) => {
|
||||||
|
topicData.mainPost = mainPosts[index];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function addFeedItem(topicData) {
|
||||||
|
const title = stripUnicodeControlChars(topicData.title);
|
||||||
const feedItem = {
|
const feedItem = {
|
||||||
title: utils.stripHTMLTags(topicData.title, utils.tags),
|
title: utils.stripHTMLTags(title, utils.tags),
|
||||||
url: `${nconf.get('url')}/topic/${topicData.slug}`,
|
url: `${nconf.get('url')}/topic/${topicData.slug}`,
|
||||||
date: new Date(topicData[timestampField]).toUTCString(),
|
date: new Date(topicData[timestampField]).toUTCString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (topicData.deleted) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (topicData.teaser && topicData.teaser.user && !feedOptions.useMainPost) {
|
if (topicData.teaser && topicData.teaser.user && !feedOptions.useMainPost) {
|
||||||
feedItem.description = topicData.teaser.content;
|
feedItem.description = stripUnicodeControlChars(topicData.teaser.content);
|
||||||
feedItem.author = topicData.teaser.user.username;
|
feedItem.author = topicData.teaser.user.username;
|
||||||
feed.item(feedItem);
|
feed.item(feedItem);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const { mainPost } = topicData;
|
||||||
const mainPost = await topics.getMainPost(topicData.tid, feedOptions.uid);
|
|
||||||
if (!mainPost) {
|
if (!mainPost) {
|
||||||
feed.item(feedItem);
|
feed.item(feedItem);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
feedItem.description = mainPost.content;
|
feedItem.description = stripUnicodeControlChars(mainPost.content);
|
||||||
feedItem.author = mainPost.user && mainPost.user.username;
|
feedItem.author = mainPost.user && mainPost.user.username;
|
||||||
feed.item(feedItem);
|
feed.item(feedItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const topicData of feedTopics) {
|
feedTopics.forEach(addFeedItem);
|
||||||
/* eslint-disable no-await-in-loop */
|
|
||||||
await addFeedItem(topicData);
|
|
||||||
}
|
|
||||||
return feed;
|
return feed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,9 +369,10 @@ function generateForPostsFeed(feedOptions, posts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
posts.forEach((postData) => {
|
posts.forEach((postData) => {
|
||||||
|
const title = stripUnicodeControlChars(postData.topic ? postData.topic.title : '');
|
||||||
feed.item({
|
feed.item({
|
||||||
title: postData.topic ? postData.topic.title : '',
|
title: title,
|
||||||
description: postData.content,
|
description: stripUnicodeControlChars(postData.content),
|
||||||
url: `${nconf.get('url')}/post/${postData.pid}`,
|
url: `${nconf.get('url')}/post/${postData.pid}`,
|
||||||
author: postData.user ? postData.user.username : '',
|
author: postData.user ? postData.user.username : '',
|
||||||
date: new Date(parseInt(postData.timestamp, 10)).toUTCString(),
|
date: new Date(parseInt(postData.timestamp, 10)).toUTCString(),
|
||||||
@@ -405,7 +407,8 @@ async function generateForTag(req, res) {
|
|||||||
return controllers404.handle404(req, res);
|
return controllers404.handle404(req, res);
|
||||||
}
|
}
|
||||||
const uid = await getUidFromToken(req);
|
const uid = await getUidFromToken(req);
|
||||||
const tag = validator.escape(String(req.params.tag));
|
const set = `tag:${String(req.params.tag)}:topics`;
|
||||||
|
const tag = validator.escape(stripUnicodeControlChars(String(req.params.tag)));
|
||||||
const page = parseInt(req.query.page, 10) || 1;
|
const page = parseInt(req.query.page, 10) || 1;
|
||||||
const topicsPerPage = meta.config.topicsPerPage || 20;
|
const topicsPerPage = meta.config.topicsPerPage || 20;
|
||||||
const start = Math.max(0, (page - 1) * topicsPerPage);
|
const start = Math.max(0, (page - 1) * topicsPerPage);
|
||||||
@@ -418,7 +421,7 @@ async function generateForTag(req, res) {
|
|||||||
site_url: `/tags/${tag}`,
|
site_url: `/tags/${tag}`,
|
||||||
start: start,
|
start: start,
|
||||||
stop: stop,
|
stop: stop,
|
||||||
}, `tag:${tag}:topics`, res);
|
}, set, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getUidFromToken(req) {
|
async function getUidFromToken(req) {
|
||||||
|
|||||||
Reference in New Issue
Block a user