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