mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: wrap generateCollection calls in try..catch to send 404 if thrown
This commit is contained in:
@@ -84,7 +84,7 @@ Actors.note = async function (req, res, next) {
|
|||||||
res.status(200).json(payload);
|
res.status(200).json(payload);
|
||||||
};
|
};
|
||||||
|
|
||||||
Actors.replies = async function (req, res) {
|
Actors.replies = async function (req, res, next) {
|
||||||
const allowed = utils.isNumber(req.params.pid) && await privileges.posts.can('topics:read', req.params.pid, activitypub._constants.uid);
|
const allowed = utils.isNumber(req.params.pid) && await privileges.posts.can('topics:read', req.params.pid, activitypub._constants.uid);
|
||||||
const exists = await posts.exists(req.params.pid);
|
const exists = await posts.exists(req.params.pid);
|
||||||
if (!allowed || !exists) {
|
if (!allowed || !exists) {
|
||||||
@@ -92,12 +92,17 @@ Actors.replies = async function (req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const page = parseInt(req.query.page, 10);
|
const page = parseInt(req.query.page, 10);
|
||||||
const replies = await activitypub.helpers.generateCollection({
|
let replies;
|
||||||
|
try {
|
||||||
|
replies = await activitypub.helpers.generateCollection({
|
||||||
set: `pid:${req.params.pid}:replies`,
|
set: `pid:${req.params.pid}:replies`,
|
||||||
page,
|
page,
|
||||||
perPage: meta.config.postsPerPage,
|
perPage: meta.config.postsPerPage,
|
||||||
url: `${nconf.get('url')}/post/${req.params.pid}/replies`,
|
url: `${nconf.get('url')}/post/${req.params.pid}/replies`,
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
return next(); // invalid page; 404
|
||||||
|
}
|
||||||
|
|
||||||
// Convert pids to urls
|
// Convert pids to urls
|
||||||
replies.orderedItems = replies.orderedItems.map(pid => (utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid));
|
replies.orderedItems = replies.orderedItems.map(pid => (utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid));
|
||||||
@@ -126,7 +131,10 @@ Actors.topic = async function (req, res, next) {
|
|||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
let [collection, pids] = await Promise.all([
|
let collection;
|
||||||
|
let pids;
|
||||||
|
try {
|
||||||
|
([collection, pids] = await Promise.all([
|
||||||
activitypub.helpers.generateCollection({
|
activitypub.helpers.generateCollection({
|
||||||
set: `tid:${req.params.tid}:posts`,
|
set: `tid:${req.params.tid}:posts`,
|
||||||
method: posts.getPidsFromSet,
|
method: posts.getPidsFromSet,
|
||||||
@@ -135,7 +143,10 @@ Actors.topic = async function (req, res, next) {
|
|||||||
url: `${nconf.get('url')}/topic/${req.params.tid}/posts`,
|
url: `${nconf.get('url')}/topic/${req.params.tid}/posts`,
|
||||||
}),
|
}),
|
||||||
db.getSortedSetMembers(`tid:${req.params.tid}:posts`),
|
db.getSortedSetMembers(`tid:${req.params.tid}:posts`),
|
||||||
]);
|
]));
|
||||||
|
} catch (e) {
|
||||||
|
return next(); // invalid page; 404
|
||||||
|
}
|
||||||
pids.push(mainPid);
|
pids.push(mainPid);
|
||||||
pids = pids.map(pid => (utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid));
|
pids = pids.map(pid => (utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid));
|
||||||
collection.totalItems += 1; // account for mainPid
|
collection.totalItems += 1; // account for mainPid
|
||||||
|
|||||||
Reference in New Issue
Block a user