diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/activitypub.ts | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts index 5c577bb61..04d85b8e6 100644 --- a/server/helpers/activitypub.ts +++ b/server/helpers/activitypub.ts | |||
@@ -2,6 +2,7 @@ import { Activity } from '../../shared/models/activitypub/activity' | |||
2 | import { ResultList } from '../../shared/models/result-list.model' | 2 | import { ResultList } from '../../shared/models/result-list.model' |
3 | import { AccountInstance } from '../models/account/account-interface' | 3 | import { AccountInstance } from '../models/account/account-interface' |
4 | import { signObject } from './peertube-crypto' | 4 | import { signObject } from './peertube-crypto' |
5 | import { ACTIVITY_PUB } from '../initializers/constants' | ||
5 | 6 | ||
6 | function activityPubContextify <T> (data: T) { | 7 | function activityPubContextify <T> (data: T) { |
7 | return Object.assign(data,{ | 8 | return Object.assign(data,{ |
@@ -24,20 +25,32 @@ function activityPubContextify <T> (data: T) { | |||
24 | } | 25 | } |
25 | 26 | ||
26 | function activityPubCollectionPagination (url: string, page: number, result: ResultList<any>) { | 27 | function activityPubCollectionPagination (url: string, page: number, result: ResultList<any>) { |
27 | const baseUrl = url.split('?').shift | 28 | let next: string |
29 | let prev: string | ||
30 | |||
31 | // There are more results | ||
32 | if (result.total > ((page + 1) * ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)) { | ||
33 | next = url + '?page=' + (page + 1) | ||
34 | } | ||
35 | |||
36 | if (page > 1) { | ||
37 | prev = url + '?page=' + (page - 1) | ||
38 | } | ||
39 | |||
40 | const orderedCollectionPagination = { | ||
41 | id: url + '?page=' + page, | ||
42 | type: 'OrderedCollectionPage', | ||
43 | prev, | ||
44 | next, | ||
45 | partOf: url, | ||
46 | orderedItems: result.data | ||
47 | } | ||
28 | 48 | ||
29 | const obj = { | 49 | const obj = { |
30 | id: baseUrl, | 50 | id: url, |
31 | type: 'Collection', | 51 | type: 'OrderedCollection', |
32 | totalItems: result.total, | 52 | totalItems: result.total, |
33 | first: { | 53 | orderedItems: orderedCollectionPagination |
34 | id: baseUrl + '?page=' + page, | ||
35 | type: 'CollectionPage', | ||
36 | totalItems: result.total, | ||
37 | next: baseUrl + '?page=' + (page + 1), | ||
38 | partOf: baseUrl, | ||
39 | items: result.data | ||
40 | } | ||
41 | } | 54 | } |
42 | 55 | ||
43 | return activityPubContextify(obj) | 56 | return activityPubContextify(obj) |