aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-11-16 15:38:09 +0100
committerChocobozzz <me@florianbigard.com>2018-11-16 15:49:16 +0100
commitbabecc3c09cd4ed06fe643a97fff4bcc31c5a9be (patch)
treeab927227a1d66dac6eb720d7ec8f2e944c51ea26 /server
parent8d4273463fb19d503b1aa0a32dc289f292ed614e (diff)
downloadPeerTube-babecc3c09cd4ed06fe643a97fff4bcc31c5a9be.tar.gz
PeerTube-babecc3c09cd4ed06fe643a97fff4bcc31c5a9be.tar.zst
PeerTube-babecc3c09cd4ed06fe643a97fff4bcc31c5a9be.zip
Fix AP collections pagination
Diffstat (limited to 'server')
-rw-r--r--server/controllers/activitypub/client.ts4
-rw-r--r--server/helpers/activitypub.ts14
-rw-r--r--server/models/activitypub/actor-follow.ts4
3 files changed, 11 insertions, 11 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts
index a342a48d4..d9d385460 100644
--- a/server/controllers/activitypub/client.ts
+++ b/server/controllers/activitypub/client.ts
@@ -298,7 +298,7 @@ async function actorFollowing (req: express.Request, actor: ActorModel) {
298 return ActorFollowModel.listAcceptedFollowingUrlsForApi([ actor.id ], undefined, start, count) 298 return ActorFollowModel.listAcceptedFollowingUrlsForApi([ actor.id ], undefined, start, count)
299 } 299 }
300 300
301 return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, handler, req.query.page) 301 return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page)
302} 302}
303 303
304async function actorFollowers (req: express.Request, actor: ActorModel) { 304async function actorFollowers (req: express.Request, actor: ActorModel) {
@@ -306,7 +306,7 @@ async function actorFollowers (req: express.Request, actor: ActorModel) {
306 return ActorFollowModel.listAcceptedFollowerUrlsForApi([ actor.id ], undefined, start, count) 306 return ActorFollowModel.listAcceptedFollowerUrlsForApi([ actor.id ], undefined, start, count)
307 } 307 }
308 308
309 return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, handler, req.query.page) 309 return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page)
310} 310}
311 311
312function videoRates (req: express.Request, rateType: VideoRateType, video: VideoModel, url: string) { 312function videoRates (req: express.Request, rateType: VideoRateType, video: VideoModel, url: string) {
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
59type ActivityPubCollectionPaginationHandler = (start: number, count: number) => Bluebird<ResultList<any>> | Promise<ResultList<any>> 59type ActivityPubCollectionPaginationHandler = (start: number, count: number) => Bluebird<ResultList<any>> | Promise<ResultList<any>>
60async function activityPubCollectionPagination (url: string, handler: ActivityPubCollectionPaginationHandler, page?: any) { 60async 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 }
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts
index 3373355ef..0a6935083 100644
--- a/server/models/activitypub/actor-follow.ts
+++ b/server/models/activitypub/actor-follow.ts
@@ -509,12 +509,12 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
509 tasks.push(ActorFollowModel.sequelize.query(query, options)) 509 tasks.push(ActorFollowModel.sequelize.query(query, options))
510 } 510 }
511 511
512 const [ followers, [ { total } ] ] = await Promise.all(tasks) 512 const [ followers, [ dataTotal ] ] = await Promise.all(tasks)
513 const urls: string[] = followers.map(f => f.url) 513 const urls: string[] = followers.map(f => f.url)
514 514
515 return { 515 return {
516 data: urls, 516 data: urls,
517 total: parseInt(total, 10) 517 total: dataTotal ? parseInt(dataTotal.total, 10) : 0
518 } 518 }
519 } 519 }
520 520