mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +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; | ||||||
| 		set: `pid:${req.params.pid}:replies`, | 	try { | ||||||
| 		page, | 		replies = await activitypub.helpers.generateCollection({ | ||||||
| 		perPage: meta.config.postsPerPage, | 			set: `pid:${req.params.pid}:replies`, | ||||||
| 		url: `${nconf.get('url')}/post/${req.params.pid}/replies`, | 			page, | ||||||
| 	}); | 			perPage: meta.config.postsPerPage, | ||||||
|  | 			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,16 +131,22 @@ Actors.topic = async function (req, res, next) { | |||||||
| 			return next(); | 			return next(); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		let [collection, pids] = await Promise.all([ | 		let collection; | ||||||
| 			activitypub.helpers.generateCollection({ | 		let pids; | ||||||
| 				set: `tid:${req.params.tid}:posts`, | 		try { | ||||||
| 				method: posts.getPidsFromSet, | 			([collection, pids] = await Promise.all([ | ||||||
| 				page, | 				activitypub.helpers.generateCollection({ | ||||||
| 				perPage, | 					set: `tid:${req.params.tid}:posts`, | ||||||
| 				url: `${nconf.get('url')}/topic/${req.params.tid}/posts`, | 					method: posts.getPidsFromSet, | ||||||
| 			}), | 					page, | ||||||
| 			db.getSortedSetMembers(`tid:${req.params.tid}:posts`), | 					perPage, | ||||||
| 		]); | 					url: `${nconf.get('url')}/topic/${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