]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/lib/activitypub/share.ts
Don't rehost announced video activities
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / share.ts
... / ...
CommitLineData
1import { Transaction } from 'sequelize'
2import { VideoPrivacy } from '../../../shared/models/videos'
3import { getServerActor } from '../../helpers/utils'
4import { VideoModel } from '../../models/video/video'
5import { VideoShareModel } from '../../models/video/video-share'
6import { sendVideoAnnounceToFollowers } from './send'
7import { getAnnounceActivityPubUrl } from './url'
8
9async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) {
10 if (video.privacy === VideoPrivacy.PRIVATE) return undefined
11
12 const serverActor = await getServerActor()
13
14 const serverShareUrl = getAnnounceActivityPubUrl(video.url, serverActor)
15 const serverSharePromise = VideoShareModel.create({
16 actorId: serverActor.id,
17 videoId: video.id,
18 url: serverShareUrl
19 }, { transaction: t })
20
21 const videoChannelShareUrl = getAnnounceActivityPubUrl(video.url, video.VideoChannel.Actor)
22 const videoChannelSharePromise = VideoShareModel.create({
23 actorId: video.VideoChannel.actorId,
24 videoId: video.id,
25 url: videoChannelShareUrl
26 }, { transaction: t })
27
28 const [ serverShare, videoChannelShare ] = await Promise.all([
29 serverSharePromise,
30 videoChannelSharePromise
31 ])
32
33 return Promise.all([
34 sendVideoAnnounceToFollowers(serverActor, videoChannelShare, video, t),
35 sendVideoAnnounceToFollowers(serverActor, serverShare, video, t)
36 ])
37}
38
39export {
40 shareVideoByServerAndChannel
41}