]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-caption.ts
Avoid concurrency issue on transcoding
[github/Chocobozzz/PeerTube.git] / server / models / video / video-caption.ts
index bbda0f3eeb60626a7607776df62ae9d913f6f20c..5fbcd6e3b9f278512ff3091b1e97dad8d01c1c8e 100644 (file)
@@ -15,9 +15,9 @@ import {
   Table,
   UpdatedAt
 } from 'sequelize-typescript'
-import { v4 as uuidv4 } from 'uuid'
 import { MVideo, MVideoCaption, MVideoCaptionFormattable, MVideoCaptionVideo } from '@server/types/models'
-import { AttributesOnly } from '@shared/core-utils'
+import { buildUUID } from '@shared/extra-utils'
+import { AttributesOnly } from '@shared/typescript-utils'
 import { VideoCaption } from '../../../shared/models/videos/caption/video-caption.model'
 import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions'
 import { logger } from '../../helpers/logger'
@@ -91,9 +91,9 @@ export class VideoCaptionModel extends Model<Partial<AttributesOnly<VideoCaption
   Video: VideoModel
 
   @BeforeDestroy
-  static async removeFiles (instance: VideoCaptionModel) {
+  static async removeFiles (instance: VideoCaptionModel, options) {
     if (!instance.Video) {
-      instance.Video = await instance.$get('Video')
+      instance.Video = await instance.$get('Video', { transaction: options.transaction })
     }
 
     if (instance.isOwned()) {
@@ -113,8 +113,7 @@ export class VideoCaptionModel extends Model<Partial<AttributesOnly<VideoCaption
     const videoInclude = {
       model: VideoModel.unscoped(),
       attributes: [ 'id', 'remote', 'uuid' ],
-      where: buildWhereIdOrUUID(videoId),
-      transaction
+      where: buildWhereIdOrUUID(videoId)
     }
 
     const query = {
@@ -123,7 +122,8 @@ export class VideoCaptionModel extends Model<Partial<AttributesOnly<VideoCaption
       },
       include: [
         videoInclude
-      ]
+      ],
+      transaction
     }
 
     return VideoCaptionModel.findOne(query)
@@ -182,7 +182,7 @@ export class VideoCaptionModel extends Model<Partial<AttributesOnly<VideoCaption
   }
 
   static generateCaptionName (language: string) {
-    return `${uuidv4()}-${language}.vtt`
+    return `${buildUUID()}-${language}.vtt`
   }
 
   isOwned () {
@@ -195,7 +195,8 @@ export class VideoCaptionModel extends Model<Partial<AttributesOnly<VideoCaption
         id: this.language,
         label: VideoCaptionModel.getLanguageLabel(this.language)
       },
-      captionPath: this.getCaptionStaticPath()
+      captionPath: this.getCaptionStaticPath(),
+      updatedAt: this.updatedAt.toISOString()
     }
   }