mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 17:37:11 +02:00
fix: off-by-one error in helpers.generateCollection, fixed incorrect totalItems count between pages in Actors.topic
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 mainPid
|
||||
if (page || collection.totalItems < perPage) {
|
||||
collection.orderedItems = collection.orderedItems || [];
|
||||
if (!page || page === 1) {
|
||||
collection.orderedItems.unshift(mainPid);
|
||||
collection.totalItems += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user