X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Fhelpers%2Factivitypub.ts;h=1188d6cf9fd46e3843d46ac7b4e3e5539d868077;hb=f2eb23cd87cf32b8fe545178143b5f49e06a58da;hp=22f8550caf37a4a343d736e0eada920e82d3c611;hpb=a15871560f80e07386c1dabb8370cd2664ecfd1f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts index 22f8550ca..1188d6cf9 100644 --- a/server/helpers/activitypub.ts +++ b/server/helpers/activitypub.ts @@ -6,17 +6,31 @@ import { ACTIVITY_PUB, REMOTE_SCHEME } from '../initializers/constants' import { signJsonLDObject } from './peertube-crypto' import { pageToStartAndCount } from './core-utils' import { URL } from 'url' -import { MActor, MVideoAccountLight } from '../typings/models' - -function activityPubContextify (data: T) { - return Object.assign(data, { - '@context': [ - 'https://www.w3.org/ns/activitystreams', - 'https://w3id.org/security/v1', - { - RsaSignature2017: 'https://w3id.org/security#RsaSignature2017', - pt: 'https://joinpeertube.org/ns#', - sc: 'http://schema.org#', +import { MActor, MVideoAccountLight } from '../types/models' +import { ContextType } from '@shared/models/activitypub/context' + +function getContextData (type: ContextType) { + const context: any[] = [ + 'https://www.w3.org/ns/activitystreams', + 'https://w3id.org/security/v1', + { + RsaSignature2017: 'https://w3id.org/security#RsaSignature2017' + } + ] + + if (type !== 'View' && type !== 'Announce') { + const additional = { + pt: 'https://joinpeertube.org/ns#', + sc: 'http://schema.org#' + } + + if (type === 'CacheFile') { + Object.assign(additional, { + expires: 'sc:expires', + CacheFile: 'pt:CacheFile' + }) + } else { + Object.assign(additional, { Hashtag: 'as:Hashtag', uuid: 'sc:identifier', category: 'sc:category', @@ -24,9 +38,21 @@ function activityPubContextify (data: T) { subtitleLanguage: 'sc:subtitleLanguage', sensitive: 'as:sensitive', language: 'sc:inLanguage', - expires: 'sc:expires', - CacheFile: 'pt:CacheFile', + + isLiveBroadcast: 'sc:isLiveBroadcast', + liveSaveReplay: { + '@type': 'sc:Boolean', + '@id': 'pt:liveSaveReplay' + }, + permanentLive: { + '@type': 'sc:Boolean', + '@id': 'pt:permanentLive' + }, + Infohash: 'pt:Infohash', + Playlist: 'pt:Playlist', + PlaylistElement: 'pt:PlaylistElement', + originallyPublishedAt: 'sc:datePublished', views: { '@type': 'sc:Number', @@ -71,9 +97,7 @@ function activityPubContextify (data: T) { support: { '@type': 'sc:Text', '@id': 'pt:support' - } - }, - { + }, likes: { '@id': 'as:likes', '@type': '@id' @@ -94,9 +118,19 @@ function activityPubContextify (data: T) { '@id': 'as:comments', '@type': '@id' } - } - ] - }) + }) + } + + context.push(additional) + } + + return { + '@context': context + } +} + +function activityPubContextify (data: T, type: ContextType = 'All') { + return Object.assign({}, data, getContextData(type)) } type ActivityPubCollectionPaginationHandler = (start: number, count: number) => Bluebird> | Promise> @@ -148,8 +182,8 @@ async function activityPubCollectionPagination ( } -function buildSignedActivity (byActor: MActor, data: Object) { - const activity = activityPubContextify(data) +function buildSignedActivity (byActor: MActor, data: Object, contextType?: ContextType) { + const activity = activityPubContextify(data, contextType) return signJsonLDObject(byActor, activity) as Promise }