1 import { Activity } from '../../shared/models/activitypub/activity'
2 import { ResultList } from '../../shared/models/result-list.model'
3 import { AccountInstance } from '../models/account/account-interface'
4 import { signObject } from './peertube-crypto'
6 function activityPubContextify <T> (data: T) {
7 return Object.assign(data,{
9 'https://www.w3.org/ns/activitystreams',
10 'https://w3id.org/security/v1',
12 'Hashtag': 'as:Hashtag',
13 'uuid': 'http://schema.org/identifier',
14 'category': 'http://schema.org/category',
15 'licence': 'http://schema.org/license',
16 'nsfw': 'as:sensitive',
17 'language': 'http://schema.org/inLanguage',
18 'views': 'http://schema.org/Number',
19 'size': 'http://schema.org/Number',
20 'VideoChannel': 'https://peertu.be/ns/VideoChannel'
26 function activityPubCollectionPagination (url: string, page: number, result: ResultList<any>) {
27 const baseUrl = url.split('?').shift
32 totalItems: result.total,
34 id: baseUrl + '?page=' + page,
35 type: 'CollectionPage',
36 totalItems: result.total,
37 next: baseUrl + '?page=' + (page + 1),
43 return activityPubContextify(obj)
46 function buildSignedActivity (byAccount: AccountInstance, data: Object) {
47 const activity = activityPubContextify(data)
49 return signObject(byAccount, activity) as Promise<Activity>
52 // ---------------------------------------------------------------------------
55 activityPubContextify,
56 activityPubCollectionPagination,