Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Fix AP collections pagination

Chocobozzzbabecc3c09cd
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts
index a342a48d40..d9d3854603 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) {
return ActorFollowModel.listAcceptedFollowingUrlsForApi([ actor.id ], undefined, start, count)
}
- return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, handler, req.query.page)
+ return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page)
}
async function actorFollowers (req: express.Request, actor: ActorModel) {
@@ -306,7 +306,7 @@ async function actorFollowers (req: express.Request, actor: ActorModel) {
return ActorFollowModel.listAcceptedFollowerUrlsForApi([ actor.id ], undefined, start, count)
}
- return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, handler, req.query.page)
+ return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page)
}
function videoRates (req: express.Request, rateType: VideoRateType, video: VideoModel, url: string) {
diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts
index 4bf6e387dd..bcbd9be59d 100644
--- a/server/helpers/activitypub.ts
+++ b/server/helpers/activitypub.ts
@@ -57,16 +57,16 @@ function activityPubContextify <T> (data: T) {
}
type ActivityPubCollectionPaginationHandler = (start: number, count: number) => Bluebird<ResultList<any>> | Promise<ResultList<any>>
-async function activityPubCollectionPagination (url: string, handler: ActivityPubCollectionPaginationHandler, page?: any) {
+async function activityPubCollectionPagination (baseUrl: string, handler: ActivityPubCollectionPaginationHandler, page?: any) {
if (!page || !validator.isInt(page)) {
// We just display the first page URL, we only need the total items
const result = await handler(0, 1)
return {
- id: url,
+ id: baseUrl,
type: 'OrderedCollection',
totalItems: result.total,
- first: url + '?page=1'
+ first: baseUrl + '?page=1'
}
}
@@ -81,19 +81,19 @@ async function activityPubCollectionPagination (url: string, handler: ActivityPu
// There are more results
if (result.total > page * ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) {
- next = url + '?page=' + (page + 1)
+ next = baseUrl + '?page=' + (page + 1)
}
if (page > 1) {
- prev = url + '?page=' + (page - 1)
+ prev = baseUrl + '?page=' + (page - 1)
}
return {
- id: url + '?page=' + page,
+ id: baseUrl + '?page=' + page,
type: 'OrderedCollectionPage',
prev,
next,
- partOf: url,
+ partOf: baseUrl,
orderedItems: result.data,
totalItems: result.total
}
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts
index 3373355eff..0a69350835 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> {
tasks.push(ActorFollowModel.sequelize.query(query, options))
}
- const [ followers, [ { total } ] ] = await Promise.all(tasks)
+ const [ followers, [ dataTotal ] ] = await Promise.all(tasks)
const urls: string[] = followers.map(f => f.url)
return {
data: urls,
- total: parseInt(total, 10)
+ total: dataTotal ? parseInt(dataTotal.total, 10) : 0
}
}