]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/videos/shared/creator.ts
Fix user subscription follows count
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / videos / shared / creator.ts
index 4f2d79374109554c84241fcbc68d1316c581e12c..ad3b889364ad40c56e640582ac955629f5a35c72 100644 (file)
@@ -1,31 +1,29 @@
 
-import { logger } from '@server/helpers/logger'
+import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger'
 import { sequelizeTypescript } from '@server/initializers/database'
 import { autoBlacklistVideoIfNeeded } from '@server/lib/video-blacklist'
 import { VideoModel } from '@server/models/video/video'
-import { MChannelAccountLight, MThumbnail, MVideoFullLight, MVideoThumbnail } from '@server/types/models'
+import { MThumbnail, MVideoFullLight, MVideoThumbnail } from '@server/types/models'
 import { VideoObject } from '@shared/models'
 import { APVideoAbstractBuilder } from './abstract-builder'
 import { getVideoAttributesFromObject } from './object-to-model-attributes'
 
 export class APVideoCreator extends APVideoAbstractBuilder {
-  protected readonly videoObject: VideoObject
-  private readonly channel: MChannelAccountLight
+  protected lTags: LoggerTagsFn
 
-  constructor (options: {
-    videoObject: VideoObject
-    channel: MChannelAccountLight
-  }) {
+  constructor (protected readonly videoObject: VideoObject) {
     super()
 
-    this.videoObject = options.videoObject
-    this.channel = options.channel
+    this.lTags = loggerTagsFactory('ap', 'video', 'create', this.videoObject.uuid, this.videoObject.id)
   }
 
   async create (waitThumbnail = false) {
-    logger.debug('Adding remote video %s.', this.videoObject.id)
+    logger.debug('Adding remote video %s.', this.videoObject.id, this.lTags())
 
-    const videoData = await getVideoAttributesFromObject(this.channel, this.videoObject, this.videoObject.to)
+    const channelActor = await this.getOrCreateVideoChannelFromVideoObject()
+    const channel = channelActor.VideoChannel
+
+    const videoData = getVideoAttributesFromObject(channel, this.videoObject, this.videoObject.to)
     const video = VideoModel.build(videoData) as MVideoThumbnail
 
     const promiseThumbnail = this.tryToGenerateThumbnail(video)
@@ -38,7 +36,7 @@ export class APVideoCreator extends APVideoAbstractBuilder {
     const { autoBlacklisted, videoCreated } = await sequelizeTypescript.transaction(async t => {
       try {
         const videoCreated = await video.save({ transaction: t }) as MVideoFullLight
-        videoCreated.VideoChannel = this.channel
+        videoCreated.VideoChannel = channel
 
         if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
 
@@ -51,7 +49,7 @@ export class APVideoCreator extends APVideoAbstractBuilder {
         await this.insertOrReplaceLive(videoCreated, t)
 
         // We added a video in this channel, set it as updated
-        await this.channel.setAsUpdated(t)
+        await channel.setAsUpdated(t)
 
         const autoBlacklisted = await autoBlacklistVideoIfNeeded({
           video: videoCreated,
@@ -61,7 +59,7 @@ export class APVideoCreator extends APVideoAbstractBuilder {
           transaction: t
         })
 
-        logger.info('Remote video with uuid %s inserted.', this.videoObject.uuid)
+        logger.info('Remote video with uuid %s inserted.', this.videoObject.uuid, this.lTags())
 
         return { autoBlacklisted, videoCreated }
       } catch (err) {