aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/activitypub.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/activitypub.ts')
-rw-r--r--server/helpers/activitypub.ts35
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'
2import { ResultList } from '../../shared/models/result-list.model' 2import { ResultList } from '../../shared/models/result-list.model'
3import { AccountInstance } from '../models/account/account-interface' 3import { AccountInstance } from '../models/account/account-interface'
4import { signObject } from './peertube-crypto' 4import { signObject } from './peertube-crypto'
5import { ACTIVITY_PUB } from '../initializers/constants'
5 6
6function activityPubContextify <T> (data: T) { 7function 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
26function activityPubCollectionPagination (url: string, page: number, result: ResultList<any>) { 27function 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)