aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/videos/shared/creator.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-02 11:54:29 +0200
committerChocobozzz <me@florianbigard.com>2021-06-02 16:57:53 +0200
commitc56faf0d9453490737f283b29a203bb1ca632b95 (patch)
tree6f6f92ae762921112e49cf5a440381053bb5a492 /server/lib/activitypub/videos/shared/creator.ts
parent08a47c75f992e7138dca5121f227909a8347d365 (diff)
downloadPeerTube-c56faf0d9453490737f283b29a203bb1ca632b95.tar.gz
PeerTube-c56faf0d9453490737f283b29a203bb1ca632b95.tar.zst
PeerTube-c56faf0d9453490737f283b29a203bb1ca632b95.zip
Move AP video channel creation
Diffstat (limited to 'server/lib/activitypub/videos/shared/creator.ts')
-rw-r--r--server/lib/activitypub/videos/shared/creator.ts21
1 files changed, 8 insertions, 13 deletions
diff --git a/server/lib/activitypub/videos/shared/creator.ts b/server/lib/activitypub/videos/shared/creator.ts
index 4f2d79374..dd9bfb508 100644
--- a/server/lib/activitypub/videos/shared/creator.ts
+++ b/server/lib/activitypub/videos/shared/creator.ts
@@ -3,29 +3,24 @@ import { logger } from '@server/helpers/logger'
3import { sequelizeTypescript } from '@server/initializers/database' 3import { sequelizeTypescript } from '@server/initializers/database'
4import { autoBlacklistVideoIfNeeded } from '@server/lib/video-blacklist' 4import { autoBlacklistVideoIfNeeded } from '@server/lib/video-blacklist'
5import { VideoModel } from '@server/models/video/video' 5import { VideoModel } from '@server/models/video/video'
6import { MChannelAccountLight, MThumbnail, MVideoFullLight, MVideoThumbnail } from '@server/types/models' 6import { MThumbnail, MVideoFullLight, MVideoThumbnail } from '@server/types/models'
7import { VideoObject } from '@shared/models' 7import { VideoObject } from '@shared/models'
8import { APVideoAbstractBuilder } from './abstract-builder' 8import { APVideoAbstractBuilder } from './abstract-builder'
9import { getVideoAttributesFromObject } from './object-to-model-attributes' 9import { getVideoAttributesFromObject } from './object-to-model-attributes'
10 10
11export class APVideoCreator extends APVideoAbstractBuilder { 11export class APVideoCreator extends APVideoAbstractBuilder {
12 protected readonly videoObject: VideoObject
13 private readonly channel: MChannelAccountLight
14 12
15 constructor (options: { 13 constructor (protected readonly videoObject: VideoObject) {
16 videoObject: VideoObject
17 channel: MChannelAccountLight
18 }) {
19 super() 14 super()
20
21 this.videoObject = options.videoObject
22 this.channel = options.channel
23 } 15 }
24 16
25 async create (waitThumbnail = false) { 17 async create (waitThumbnail = false) {
26 logger.debug('Adding remote video %s.', this.videoObject.id) 18 logger.debug('Adding remote video %s.', this.videoObject.id)
27 19
28 const videoData = await getVideoAttributesFromObject(this.channel, this.videoObject, this.videoObject.to) 20 const channelActor = await this.getOrCreateVideoChannelFromVideoObject()
21 const channel = channelActor.VideoChannel
22
23 const videoData = await getVideoAttributesFromObject(channel, this.videoObject, this.videoObject.to)
29 const video = VideoModel.build(videoData) as MVideoThumbnail 24 const video = VideoModel.build(videoData) as MVideoThumbnail
30 25
31 const promiseThumbnail = this.tryToGenerateThumbnail(video) 26 const promiseThumbnail = this.tryToGenerateThumbnail(video)
@@ -38,7 +33,7 @@ export class APVideoCreator extends APVideoAbstractBuilder {
38 const { autoBlacklisted, videoCreated } = await sequelizeTypescript.transaction(async t => { 33 const { autoBlacklisted, videoCreated } = await sequelizeTypescript.transaction(async t => {
39 try { 34 try {
40 const videoCreated = await video.save({ transaction: t }) as MVideoFullLight 35 const videoCreated = await video.save({ transaction: t }) as MVideoFullLight
41 videoCreated.VideoChannel = this.channel 36 videoCreated.VideoChannel = channel
42 37
43 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) 38 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
44 39
@@ -51,7 +46,7 @@ export class APVideoCreator extends APVideoAbstractBuilder {
51 await this.insertOrReplaceLive(videoCreated, t) 46 await this.insertOrReplaceLive(videoCreated, t)
52 47
53 // We added a video in this channel, set it as updated 48 // We added a video in this channel, set it as updated
54 await this.channel.setAsUpdated(t) 49 await channel.setAsUpdated(t)
55 50
56 const autoBlacklisted = await autoBlacklistVideoIfNeeded({ 51 const autoBlacklisted = await autoBlacklistVideoIfNeeded({
57 video: videoCreated, 52 video: videoCreated,