aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/videos/shared/abstract-builder.ts25
1 files changed, 21 insertions, 4 deletions
diff --git a/server/lib/activitypub/videos/shared/abstract-builder.ts b/server/lib/activitypub/videos/shared/abstract-builder.ts
index 22280fce1..e89c94bcd 100644
--- a/server/lib/activitypub/videos/shared/abstract-builder.ts
+++ b/server/lib/activitypub/videos/shared/abstract-builder.ts
@@ -75,11 +75,28 @@ export abstract class APVideoAbstractBuilder {
75 } 75 }
76 76
77 protected async insertOrReplaceCaptions (video: MVideoFullLight, t: Transaction) { 77 protected async insertOrReplaceCaptions (video: MVideoFullLight, t: Transaction) {
78 const videoCaptionsPromises = getCaptionAttributesFromObject(video, this.videoObject) 78 const existingCaptions = await VideoCaptionModel.listVideoCaptions(video.id, t)
79 .map(a => new VideoCaptionModel(a) as MVideoCaption)
80 .map(c => VideoCaptionModel.insertOrReplaceLanguage(c, t))
81 79
82 await Promise.all(videoCaptionsPromises) 80 let captionsToCreate = getCaptionAttributesFromObject(video, this.videoObject)
81 .map(a => new VideoCaptionModel(a) as MVideoCaption)
82
83 for (const existingCaption of existingCaptions) {
84 // Only keep captions that do not already exist
85 const filtered = captionsToCreate.filter(c => !c.isEqual(existingCaption))
86
87 // This caption already exists, we don't need to destroy and create it
88 if (filtered.length !== captionsToCreate.length) {
89 captionsToCreate = filtered
90 continue
91 }
92
93 // Destroy this caption that does not exist anymore
94 await existingCaption.destroy({ transaction: t })
95 }
96
97 for (const captionToCreate of captionsToCreate) {
98 await captionToCreate.save({ transaction: t })
99 }
83 } 100 }
84 101
85 protected async insertOrReplaceLive (video: MVideoFullLight, transaction: Transaction) { 102 protected async insertOrReplaceLive (video: MVideoFullLight, transaction: Transaction) {