Fix AP collections pagination
This commit is contained in:
parent
8d4273463f
commit
babecc3c09
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue