1 import { Transaction } from 'sequelize/types'
2 import { isArray } from '@server/helpers/custom-validators/misc'
3 import { MVideoAP, MVideoAPWithoutCaption } from '@server/types/models'
4 import { sendCreateVideo, sendUpdateVideo } from '../send'
5 import { shareVideoByServerAndChannel } from '../share'
7 async function federateVideoIfNeeded (videoArg: MVideoAPWithoutCaption, isNewVideo: boolean, transaction?: Transaction) {
8 const video = videoArg as MVideoAP
11 // Check this is not a blacklisted video, or unfederated blacklisted video
12 (video.isBlacklisted() === false || (isNewVideo === false && video.VideoBlacklist.unfederated === false)) &&
13 // Check the video is public/unlisted and published
14 video.hasPrivacyForFederation() && video.hasStateForFederation()
16 // Fetch more attributes that we will need to serialize in AP object
17 if (isArray(video.VideoCaptions) === false) {
18 video.VideoCaptions = await video.$get('VideoCaptions', {
19 attributes: [ 'filename', 'language' ],
25 // Now we'll add the video's meta data to our followers
26 await sendCreateVideo(video, transaction)
27 await shareVideoByServerAndChannel(video, transaction)
29 await sendUpdateVideo(video, transaction)