]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/video-blacklist.ts
Fix tests
[github/Chocobozzz/PeerTube.git] / server / lib / video-blacklist.ts
index f6c66b6dd8a658d3391440927f0c3537c64aa6c6..cb1ea834c46dc32a0b5f52a875999db98fe961f3 100644 (file)
@@ -1,4 +1,5 @@
 import { Transaction } from 'sequelize'
+import { afterCommitIfTransaction } from '@server/helpers/database-utils'
 import { sequelizeTypescript } from '@server/initializers/database'
 import {
   MUser,
@@ -8,16 +9,18 @@ import {
   MVideoFullLight,
   MVideoWithBlacklistLight
 } from '@server/types/models'
-import { UserRight, VideoBlacklistCreate, VideoBlacklistType } from '../../shared/models'
+import { LiveVideoError, UserRight, VideoBlacklistCreate, VideoBlacklistType } from '../../shared/models'
 import { UserAdminFlag } from '../../shared/models/users/user-flag.model'
-import { logger } from '../helpers/logger'
+import { logger, loggerTagsFactory } from '../helpers/logger'
 import { CONFIG } from '../initializers/config'
 import { VideoBlacklistModel } from '../models/video/video-blacklist'
 import { sendDeleteVideo } from './activitypub/send'
 import { federateVideoIfNeeded } from './activitypub/videos'
+import { LiveManager } from './live/live-manager'
 import { Notifier } from './notifier'
 import { Hooks } from './plugins/hooks'
-import { LiveManager } from './live-manager'
+
+const lTags = loggerTagsFactory('blacklist')
 
 async function autoBlacklistVideoIfNeeded (parameters: {
   video: MVideoWithBlacklistLight
@@ -53,9 +56,13 @@ async function autoBlacklistVideoIfNeeded (parameters: {
 
   videoBlacklist.Video = video
 
-  if (notify) Notifier.Instance.notifyOnVideoAutoBlacklist(videoBlacklist)
+  if (notify) {
+    afterCommitIfTransaction(transaction, () => {
+      Notifier.Instance.notifyOnVideoAutoBlacklist(videoBlacklist)
+    })
+  }
 
-  logger.info('Video %s auto-blacklisted.', video.uuid)
+  logger.info('Video %s auto-blacklisted.', video.uuid, lTags(video.uuid))
 
   return true
 }
@@ -66,8 +73,7 @@ async function blacklistVideo (videoInstance: MVideoAccountLight, options: Video
     unfederated: options.unfederate === true,
     reason: options.reason,
     type: VideoBlacklistType.MANUAL
-  }
-  )
+  })
   blacklist.Video = videoInstance
 
   if (options.unfederate === true) {
@@ -75,7 +81,7 @@ async function blacklistVideo (videoInstance: MVideoAccountLight, options: Video
   }
 
   if (videoInstance.isLive) {
-    LiveManager.Instance.stopSessionOf(videoInstance.id)
+    LiveManager.Instance.stopSessionOf(videoInstance.uuid, LiveVideoError.BLACKLISTED)
   }
 
   Notifier.Instance.notifyOnVideoBlacklist(blacklist)