async function onVideoFileTranscoderOrImportSuccess (video: VideoModel) {
if (video === undefined) return undefined
- const { videoDatabase, isNewVideo } = await sequelizeTypescript.transaction(async t => {
+ const { videoDatabase, videoPublished } = await sequelizeTypescript.transaction(async t => {
// Maybe the video changed in database, refresh it
let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t)
// Video does not exist anymore
if (!videoDatabase) return undefined
- let isNewVideo = false
+ let videoPublished = false
// We transcoded the video file in another format, now we can publish it
if (videoDatabase.state !== VideoState.PUBLISHED) {
- isNewVideo = true
+ videoPublished = true
videoDatabase.state = VideoState.PUBLISHED
videoDatabase.publishedAt = new Date()
}
// If the video was not published, we consider it is a new one for other instances
- await federateVideoIfNeeded(videoDatabase, isNewVideo, t)
+ await federateVideoIfNeeded(videoDatabase, videoPublished, t)
- return { videoDatabase, isNewVideo }
+ return { videoDatabase, videoPublished }
})
- if (isNewVideo) Notifier.Instance.notifyOnNewVideo(videoDatabase)
+ if (videoPublished) {
+ Notifier.Instance.notifyOnNewVideo(videoDatabase)
+ Notifier.Instance.notifyOnPendingVideoPublished(videoDatabase)
+ }
}
async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: boolean) {
// Outside the transaction (IO on disk)
const { videoFileResolution } = await videoArg.getOriginalFileResolution()
- const videoDatabase = await sequelizeTypescript.transaction(async t => {
+ const { videoDatabase, videoPublished } = await sequelizeTypescript.transaction(async t => {
// Maybe the video changed in database, refresh it
let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoArg.uuid, t)
// Video does not exist anymore
{ resolutions: resolutionsEnabled }
)
+ let videoPublished = false
+
if (resolutionsEnabled.length !== 0) {
const tasks: Bluebird<Bull.Job<any>>[] = []
logger.info('Transcoding jobs created for uuid %s.', videoDatabase.uuid, { resolutionsEnabled })
} else {
+ videoPublished = true
+
// No transcoding to do, it's now published
videoDatabase.state = VideoState.PUBLISHED
videoDatabase = await videoDatabase.save({ transaction: t })
await federateVideoIfNeeded(videoDatabase, isNewVideo, t)
- return videoDatabase
+ return { videoDatabase, videoPublished }
})
if (isNewVideo) Notifier.Instance.notifyOnNewVideo(videoDatabase)
+ if (videoPublished) Notifier.Instance.notifyOnPendingVideoPublished(videoDatabase)
}
// ---------------------------------------------------------------------------