]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/videos/updater.ts
Update server dependencies
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / videos / updater.ts
index f786bb196efc73573e8b263c2493d5455b9e9d74..6ddd2301b0e917421e7c8a978089704905e8b391 100644 (file)
@@ -3,18 +3,17 @@ import { resetSequelizeInstance, runInReadCommittedTransaction } from '@server/h
 import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger'
 import { Notifier } from '@server/lib/notifier'
 import { PeerTubeSocket } from '@server/lib/peertube-socket'
+import { Hooks } from '@server/lib/plugins/hooks'
 import { autoBlacklistVideoIfNeeded } from '@server/lib/video-blacklist'
 import { VideoLiveModel } from '@server/models/video/video-live'
 import { MActor, MChannelAccountLight, MChannelId, MVideoAccountLightBlacklistAllFiles, MVideoFullLight } from '@server/types/models'
 import { VideoObject, VideoPrivacy } from '@shared/models'
-import { APVideoAbstractBuilder, getVideoAttributesFromObject } from './shared'
+import { APVideoAbstractBuilder, getVideoAttributesFromObject, updateVideoRates } from './shared'
 
 export class APVideoUpdater extends APVideoAbstractBuilder {
   private readonly wasPrivateVideo: boolean
   private readonly wasUnlistedVideo: boolean
 
-  private readonly videoFieldsSave: any
-
   private readonly oldVideoChannel: MChannelAccountLight
 
   protected lTags: LoggerTagsFn
@@ -30,8 +29,6 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
 
     this.oldVideoChannel = this.video.VideoChannel
 
-    this.videoFieldsSave = this.video.toJSON()
-
     this.lTags = loggerTagsFactory('ap', 'video', 'update', video.uuid, video.url)
   }
 
@@ -74,6 +71,8 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
         transaction: undefined
       })
 
+      await updateVideoRates(videoUpdated, this.videoObject)
+
       // Notify our users?
       if (this.wasPrivateVideo || this.wasUnlistedVideo) {
         Notifier.Instance.notifyOnNewVideoIfNeeded(videoUpdated)
@@ -83,11 +82,13 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
         PeerTubeSocket.Instance.sendVideoLiveNewState(videoUpdated)
       }
 
+      Hooks.runAction('action:activity-pub.remote-video.updated', { video: videoUpdated, videoAPObject: this.videoObject })
+
       logger.info('Remote video with uuid %s updated', this.videoObject.uuid, this.lTags())
 
       return videoUpdated
     } catch (err) {
-      this.catchUpdateError(err)
+      await this.catchUpdateError(err)
     }
   }
 
@@ -153,9 +154,9 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
     videoUpdated.VideoLive = null
   }
 
-  private catchUpdateError (err: Error) {
-    if (this.video !== undefined && this.videoFieldsSave !== undefined) {
-      resetSequelizeInstance(this.video, this.videoFieldsSave)
+  private async catchUpdateError (err: Error) {
+    if (this.video !== undefined) {
+      await resetSequelizeInstance(this.video)
     }
 
     // This is just a debug because we will retry the insert