aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/videos/federate.ts
blob: bd0c54b0c765bf66e195229d61a4a4a6cb9962f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Transaction } from 'sequelize/types'
import { isArray } from '@server/helpers/custom-validators/misc'
import { MVideoAP, MVideoAPWithoutCaption } from '@server/types/models'
import { sendCreateVideo, sendUpdateVideo } from '../send'
import { shareVideoByServerAndChannel } from '../share'

async function federateVideoIfNeeded (videoArg: MVideoAPWithoutCaption, isNewVideo: boolean, transaction?: Transaction) {
  const video = videoArg as MVideoAP

  if (
    // Check this is not a blacklisted video, or unfederated blacklisted video
    (video.isBlacklisted() === false || (isNewVideo === false && video.VideoBlacklist.unfederated === false)) &&
    // Check the video is public/unlisted and published
    video.hasPrivacyForFederation() && video.hasStateForFederation()
  ) {
    // Fetch more attributes that we will need to serialize in AP object
    if (isArray(video.VideoCaptions) === false) {
      video.VideoCaptions = await video.$get('VideoCaptions', {
        attributes: [ 'filename', 'language' ],
        transaction
      })
    }

    if (isNewVideo) {
      // Now we'll add the video's meta data to our followers
      await sendCreateVideo(video, transaction)
      await shareVideoByServerAndChannel(video, transaction)
    } else {
      await sendUpdateVideo(video, transaction)
    }
  }
}

export {
  federateVideoIfNeeded
}