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) {
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) {
}
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'
}
}
// 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
}
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
}
}