1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 02:09:37 +02:00

Add outbox page size parameter

This commit is contained in:
Rigel Kent 2020-01-09 00:43:52 +01:00 committed by Chocobozzz
parent c08579e14f
commit fbc77eb648
4 changed files with 36 additions and 4 deletions

View file

@ -100,7 +100,12 @@ function activityPubContextify <T> (data: T) {
}
type ActivityPubCollectionPaginationHandler = (start: number, count: number) => Bluebird<ResultList<any>> | Promise<ResultList<any>>
async function activityPubCollectionPagination (baseUrl: string, handler: ActivityPubCollectionPaginationHandler, page?: any) {
async function activityPubCollectionPagination (
baseUrl: string,
handler: ActivityPubCollectionPaginationHandler,
page?: any,
size = ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE
) {
if (!page || !validator.isInt(page)) {
// We just display the first page URL, we only need the total items
const result = await handler(0, 1)
@ -113,7 +118,7 @@ async function activityPubCollectionPagination (baseUrl: string, handler: Activi
}
}
const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
const { start, count } = pageToStartAndCount(page, size)
const result = await handler(start, count)
let next: string | undefined
@ -123,7 +128,7 @@ async function activityPubCollectionPagination (baseUrl: string, handler: Activi
page = parseInt(page, 10)
// There are more results
if (result.total > page * ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) {
if (result.total > page * size) {
next = baseUrl + '?page=' + (page + 1)
}