2021-06-02 02:35:01 -05:00
|
|
|
import { Transaction } from 'sequelize/types'
|
2023-06-01 07:51:16 -05:00
|
|
|
import { MVideoAP, MVideoAPLight } from '@server/types/models'
|
2021-06-02 02:35:01 -05:00
|
|
|
import { sendCreateVideo, sendUpdateVideo } from '../send'
|
|
|
|
import { shareVideoByServerAndChannel } from '../share'
|
|
|
|
|
2023-06-01 07:51:16 -05:00
|
|
|
async function federateVideoIfNeeded (videoArg: MVideoAPLight, isNewVideo: boolean, transaction?: Transaction) {
|
2021-06-02 02:35:01 -05:00
|
|
|
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()
|
|
|
|
) {
|
2023-06-01 07:51:16 -05:00
|
|
|
const video = await videoArg.lightAPToFullAP(transaction)
|
2021-06-02 02:35:01 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|