]>
Commit | Line | Data |
---|---|---|
69290ab3 C |
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' | |
6 | ||
7 | async function federateVideoIfNeeded (videoArg: MVideoAPWithoutCaption, isNewVideo: boolean, transaction?: Transaction) { | |
8 | const video = videoArg as MVideoAP | |
9 | ||
10 | if ( | |
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() | |
15 | ) { | |
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' ], | |
20 | transaction | |
21 | }) | |
22 | } | |
23 | ||
24 | if (isNewVideo) { | |
25 | // Now we'll add the video's meta data to our followers | |
26 | await sendCreateVideo(video, transaction) | |
27 | await shareVideoByServerAndChannel(video, transaction) | |
28 | } else { | |
29 | await sendUpdateVideo(video, transaction) | |
30 | } | |
31 | } | |
32 | } | |
33 | ||
34 | export { | |
35 | federateVideoIfNeeded | |
36 | } |