diff options
author | Chocobozzz <me@florianbigard.com> | 2018-11-16 15:38:09 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-11-16 15:49:16 +0100 |
commit | babecc3c09cd4ed06fe643a97fff4bcc31c5a9be (patch) | |
tree | ab927227a1d66dac6eb720d7ec8f2e944c51ea26 /server/helpers | |
parent | 8d4273463fb19d503b1aa0a32dc289f292ed614e (diff) | |
download | PeerTube-babecc3c09cd4ed06fe643a97fff4bcc31c5a9be.tar.gz PeerTube-babecc3c09cd4ed06fe643a97fff4bcc31c5a9be.tar.zst PeerTube-babecc3c09cd4ed06fe643a97fff4bcc31c5a9be.zip |
Fix AP collections pagination
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/activitypub.ts | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts index 4bf6e387d..bcbd9be59 100644 --- a/server/helpers/activitypub.ts +++ b/server/helpers/activitypub.ts | |||
@@ -57,16 +57,16 @@ function activityPubContextify <T> (data: T) { | |||
57 | } | 57 | } |
58 | 58 | ||
59 | type ActivityPubCollectionPaginationHandler = (start: number, count: number) => Bluebird<ResultList<any>> | Promise<ResultList<any>> | 59 | type ActivityPubCollectionPaginationHandler = (start: number, count: number) => Bluebird<ResultList<any>> | Promise<ResultList<any>> |
60 | async function activityPubCollectionPagination (url: string, handler: ActivityPubCollectionPaginationHandler, page?: any) { | 60 | async function activityPubCollectionPagination (baseUrl: string, handler: ActivityPubCollectionPaginationHandler, page?: any) { |
61 | if (!page || !validator.isInt(page)) { | 61 | if (!page || !validator.isInt(page)) { |
62 | // We just display the first page URL, we only need the total items | 62 | // We just display the first page URL, we only need the total items |
63 | const result = await handler(0, 1) | 63 | const result = await handler(0, 1) |
64 | 64 | ||
65 | return { | 65 | return { |
66 | id: url, | 66 | id: baseUrl, |
67 | type: 'OrderedCollection', | 67 | type: 'OrderedCollection', |
68 | totalItems: result.total, | 68 | totalItems: result.total, |
69 | first: url + '?page=1' | 69 | first: baseUrl + '?page=1' |
70 | } | 70 | } |
71 | } | 71 | } |
72 | 72 | ||
@@ -81,19 +81,19 @@ async function activityPubCollectionPagination (url: string, handler: ActivityPu | |||
81 | 81 | ||
82 | // There are more results | 82 | // There are more results |
83 | if (result.total > page * ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) { | 83 | if (result.total > page * ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) { |
84 | next = url + '?page=' + (page + 1) | 84 | next = baseUrl + '?page=' + (page + 1) |
85 | } | 85 | } |
86 | 86 | ||
87 | if (page > 1) { | 87 | if (page > 1) { |
88 | prev = url + '?page=' + (page - 1) | 88 | prev = baseUrl + '?page=' + (page - 1) |
89 | } | 89 | } |
90 | 90 | ||
91 | return { | 91 | return { |
92 | id: url + '?page=' + page, | 92 | id: baseUrl + '?page=' + page, |
93 | type: 'OrderedCollectionPage', | 93 | type: 'OrderedCollectionPage', |
94 | prev, | 94 | prev, |
95 | next, | 95 | next, |
96 | partOf: url, | 96 | partOf: baseUrl, |
97 | orderedItems: result.data, | 97 | orderedItems: result.data, |
98 | totalItems: result.total | 98 | totalItems: result.total |
99 | } | 99 | } |