Node.js based forum software built for the modern web
fix: off-by-one error in helpers.generateCollection, fixed incorrect totalItems count between pages in Actors.topic
Julian Lam5a0491687934
diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.jsindex 3b6e7549aa..d06a058201 100644--- a/src/activitypub/helpers.js+++ b/src/activitypub/helpers.js@@ -483,14 +483,15 @@ Helpers.generateCollection = async ({ set, method, count, page, perPage, url })paginate = false;}- page = parseInt(page, 10) || undefined;+ page = parseInt(page, 10) || 1;+ page = Math.max(1, Math.min(page, pageCount));if (page) {const invalidPagination = page < 1 || page > pageCount;if (invalidPagination) {throw new Error('[[error:invalid-data]]');}- const start = Math.max(0, ((page - 1) * perPage) - 1);+ const start = Math.max(0, (page - 1) * perPage);const stop = Math.max(0, start + perPage - 1);items = await method.call(null, start, stop);}diff --git a/src/controllers/activitypub/actors.js b/src/controllers/activitypub/actors.jsindex dddd402f2d..6745d42290 100644--- a/src/controllers/activitypub/actors.js+++ b/src/controllers/activitypub/actors.js@@ -150,10 +150,10 @@ Actors.topic = async function (req, res, next) {} catch (e) {return next(); // invalid page; 404}- pids.push(mainPid);- pids = pids.map(pid => (utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid));// Generate digest for ETag+ pids.push(mainPid);+ pids = pids.map(pid => (utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid));const digest = activitypub.helpers.generateDigest(new Set(pids));const ifNoneMatch = (req.get('If-None-Match') || '').split(',').map((tag) => {tag = tag.trim();@@ -169,11 +169,11 @@ Actors.topic = async function (req, res, next) {res.set('ETag', digest);// Add OP to collection on first (or only) page+ collection.totalItems += 1; // account for mainPidif (page || collection.totalItems < perPage) {collection.orderedItems = collection.orderedItems || [];if (!page || page === 1) {collection.orderedItems.unshift(mainPid);- collection.totalItems += 1;}}