X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Factivitypub.ts;h=fe721cbac1f01e351d157dd8a7d965c45ffd8c1d;hb=743dab5517d4501f6b35cfc795de6c8b6f41ebb3;hp=d28453d793f405a42f6b355ba4cdaccc1cc3514f;hpb=26d6bf6533023326fa017812cf31bbe20c752d36;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts index d28453d79..fe721cbac 100644 --- a/server/helpers/activitypub.ts +++ b/server/helpers/activitypub.ts @@ -1,13 +1,12 @@ -import * as Bluebird from 'bluebird' +import Bluebird from 'bluebird' +import { URL } from 'url' import validator from 'validator' +import { ContextType } from '@shared/models/activitypub/context' import { ResultList } from '../../shared/models' -import { Activity } from '../../shared/models/activitypub' import { ACTIVITY_PUB, REMOTE_SCHEME } from '../initializers/constants' -import { signJsonLDObject } from './peertube-crypto' +import { MActor, MVideoWithHost } from '../types/models' import { pageToStartAndCount } from './core-utils' -import { URL } from 'url' -import { MActor, MVideoAccountLight } from '../types/models' -import { ContextType } from '@shared/models/activitypub/context' +import { signJsonLDObject } from './peertube-crypto' function getContextData (type: ContextType) { const context: any[] = [ @@ -39,6 +38,16 @@ function getContextData (type: ContextType) { sensitive: 'as:sensitive', language: 'sc:inLanguage', + 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', @@ -172,16 +181,16 @@ async function activityPubCollectionPagination ( } -function buildSignedActivity (byActor: MActor, data: Object, contextType?: ContextType) { +function buildSignedActivity (byActor: MActor, data: T, contextType?: ContextType) { const activity = activityPubContextify(data, contextType) - return signJsonLDObject(byActor, activity) as Promise + return signJsonLDObject(byActor, activity) } -function getAPId (activity: string | { id: string }) { - if (typeof activity === 'string') return activity +function getAPId (object: string | { id: string }) { + if (typeof object === 'string') return object - return activity.id + return object.id } function checkUrlsSameHost (url1: string, url2: string) { @@ -191,10 +200,12 @@ function checkUrlsSameHost (url1: string, url2: string) { return idHost && actorHost && idHost.toLowerCase() === actorHost.toLowerCase() } -function buildRemoteVideoBaseUrl (video: MVideoAccountLight, path: string) { - const host = video.VideoChannel.Account.Actor.Server.host +function buildRemoteVideoBaseUrl (video: MVideoWithHost, path: string, scheme?: string) { + if (!scheme) scheme = REMOTE_SCHEME.HTTP + + const host = video.VideoChannel.Actor.Server.host - return REMOTE_SCHEME.HTTP + '://' + host + path + return scheme + '://' + host + path } // ---------------------------------------------------------------------------