1 import { ResultList } from '../../shared/models'
2 import { Activity } from '../../shared/models/activitypub'
3 import { ACTIVITY_PUB } from '../initializers'
4 import { ActorModel } from '../models/activitypub/actor'
5 import { signObject } from './peertube-crypto'
7 function activityPubContextify <T> (data: T) {
8 return Object.assign(data,{
10 'https://www.w3.org/ns/activitystreams',
11 'https://w3id.org/security/v1',
13 'RsaSignature2017': 'https://w3id.org/security#RsaSignature2017',
14 'Hashtag': 'as:Hashtag',
15 'uuid': 'http://schema.org/identifier',
16 'category': 'http://schema.org/category',
17 'licence': 'http://schema.org/license',
18 'sensitive': 'as:sensitive',
19 'language': 'http://schema.org/inLanguage',
20 'views': 'http://schema.org/Number',
21 'size': 'http://schema.org/Number',
22 'commentsEnabled': 'http://schema.org/Boolean'
28 function activityPubCollection (url: string, results: any[]) {
31 type: 'OrderedCollection',
32 totalItems: results.length,
37 function activityPubCollectionPagination (url: string, page: any, result: ResultList<any>) {
41 // Assert page is a number
42 page = parseInt(page, 10)
44 // There are more results
45 if (result.total > page * ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) {
46 next = url + '?page=' + (page + 1)
50 prev = url + '?page=' + (page - 1)
53 const orderedCollectionPagination = {
54 id: url + '?page=' + page,
55 type: 'OrderedCollectionPage',
59 orderedItems: result.data
63 return activityPubContextify({
65 type: 'OrderedCollection',
66 totalItems: result.total,
67 first: orderedCollectionPagination
70 orderedCollectionPagination['totalItems'] = result.total
73 return orderedCollectionPagination
76 function buildSignedActivity (byActor: ActorModel, data: Object) {
77 const activity = activityPubContextify(data)
79 return signObject(byActor, activity) as Promise<Activity>
82 // ---------------------------------------------------------------------------
85 activityPubContextify,
86 activityPubCollectionPagination,
87 activityPubCollection,