]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/video.ts
Add check constraints live tests
[github/Chocobozzz/PeerTube.git] / server / lib / video.ts
index 81b7c41592c5c35e2b87fc6ca27b5f115556cc7e..8d9918b2d9315465aab3bd8d5aa12bdf77115c46 100644 (file)
@@ -4,7 +4,7 @@ import { TagModel } from '@server/models/video/tag'
 import { VideoModel } from '@server/models/video/video'
 import { FilteredModelAttributes } from '@server/types'
 import { MTag, MThumbnail, MVideoTag, MVideoThumbnail, MVideoUUID } from '@server/types/models'
-import { ThumbnailType, VideoCreate, VideoPrivacy } from '@shared/models'
+import { ThumbnailType, VideoCreate, VideoPrivacy, VideoState } from '@shared/models'
 import { federateVideoIfNeeded } from './activitypub/videos'
 import { Notifier } from './notifier'
 import { createVideoMiniatureFromExisting } from './thumbnail'
@@ -81,8 +81,8 @@ async function setVideoTags (options: {
   }
 }
 
-async function publishAndFederateIfNeeded (video: MVideoUUID) {
-  const { videoDatabase, videoPublished } = await sequelizeTypescript.transaction(async t => {
+async function publishAndFederateIfNeeded (video: MVideoUUID, wasLive = false) {
+  const result = await sequelizeTypescript.transaction(async t => {
     // Maybe the video changed in database, refresh it
     const videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t)
     // Video does not exist anymore
@@ -92,14 +92,15 @@ async function publishAndFederateIfNeeded (video: MVideoUUID) {
     const videoPublished = await videoDatabase.publishIfNeededAndSave(t)
 
     // If the video was not published, we consider it is a new one for other instances
-    await federateVideoIfNeeded(videoDatabase, videoPublished, t)
+    // Live videos are always federated, so it's not a new video
+    await federateVideoIfNeeded(videoDatabase, !wasLive && videoPublished, t)
 
     return { videoDatabase, videoPublished }
   })
 
-  if (videoPublished) {
-    Notifier.Instance.notifyOnNewVideoIfNeeded(videoDatabase)
-    Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(videoDatabase)
+  if (result?.videoPublished) {
+    Notifier.Instance.notifyOnNewVideoIfNeeded(result.videoDatabase)
+    Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(result.videoDatabase)
   }
 }