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 'nsfw': 'as:sensitive',
19 'language': 'http://schema.org/inLanguage',
20 'views': 'http://schema.org/Number',
21 'size': 'http://schema.org/Number'
27 function activityPubCollection (results: any[]) {
29 type: 'OrderedCollection',
30 totalItems: results.length,
35 function activityPubCollectionPagination (url: string, page: any, result: ResultList<any>) {
39 // Assert page is a number
40 page = parseInt(page, 10)
42 // There are more results
43 if (result.total > page * ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) {
44 next = url + '?page=' + (page + 1)
48 prev = url + '?page=' + (page - 1)
51 const orderedCollectionPagination = {
52 id: url + '?page=' + page,
53 type: 'OrderedCollectionPage',
57 orderedItems: result.data
61 return activityPubContextify({
63 type: 'OrderedCollection',
64 totalItems: result.total,
65 first: orderedCollectionPagination
68 orderedCollectionPagination['totalItems'] = result.total
71 return orderedCollectionPagination
74 function buildSignedActivity (byActor: ActorModel, data: Object) {
75 const activity = activityPubContextify(data)
77 return signObject(byActor, activity) as Promise<Activity>
80 // ---------------------------------------------------------------------------
83 activityPubContextify,
84 activityPubCollectionPagination,
85 activityPubCollection,