From d685b20e0aa1d13db44fa8bc6646fc23750bdafe Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 4 Nov 2024 13:43:28 -0500 Subject: [PATCH] fix: #12893, topic with pages returning OrderedCollectionPage instead of OrderedCollection. Turns out empty arrays are still truthy, heh. --- src/activitypub/helpers.js | 2 +- src/controllers/activitypub/actors.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.js index 6f597ee772..5165a9c166 100644 --- a/src/activitypub/helpers.js +++ b/src/activitypub/helpers.js @@ -429,7 +429,7 @@ Helpers.generateCollection = async ({ set, method, page, perPage, url }) => { } const object = { - type: paginate && items ? 'OrderedCollectionPage' : 'OrderedCollection', + type: paginate && items.length ? 'OrderedCollectionPage' : 'OrderedCollection', totalItems: count, }; diff --git a/src/controllers/activitypub/actors.js b/src/controllers/activitypub/actors.js index b477069927..c80f6e2867 100644 --- a/src/controllers/activitypub/actors.js +++ b/src/controllers/activitypub/actors.js @@ -118,7 +118,7 @@ Actors.topic = async function (req, res, next) { return res.sendStatus(404); } - const page = parseInt(req.query.page, 10); + const page = parseInt(req.query.page, 10) || undefined; const perPage = meta.config.postsPerPage; const { cid, titleRaw: name, mainPid, slug } = await topics.getTopicFields(req.params.tid, ['cid', 'title', 'mainPid', 'slug']); try { @@ -132,10 +132,11 @@ Actors.topic = async function (req, res, next) { }), db.getSortedSetMembers(`tid:${req.params.tid}:posts`), ]); - - // Generate digest for ETag pids.push(mainPid); pids = pids.map(pid => (utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid)); + collection.totalItems += 1; // account for mainPid + + // Generate digest for ETag const digest = activitypub.helpers.generateDigest(new Set(pids)); const ifNoneMatch = (req.get('If-None-Match') || '').split(',').map((tag) => { tag = tag.trim(); @@ -151,7 +152,6 @@ Actors.topic = async function (req, res, next) { res.set('ETag', digest); // Convert pids to urls - collection.totalItems += 1; if (page || collection.totalItems < meta.config.postsPerPage) { collection.orderedItems = collection.orderedItems || []; if (!page || page === 1) { // add OP to collection