]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/redundancy/video-redundancy.ts
Delete correctly redundancy files
[github/Chocobozzz/PeerTube.git] / server / models / redundancy / video-redundancy.ts
index c23a9cc17f26417b57c8dd870ee9f6e3d3bfe99c..da1c6f4a7f11d844e5047049e44aecdffd538f10 100644 (file)
@@ -1,6 +1,6 @@
 import {
-  AfterDestroy,
   AllowNull,
+  BeforeDestroy,
   BelongsTo,
   Column,
   CreatedAt,
@@ -115,14 +115,16 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
   })
   Actor: ActorModel
 
-  @AfterDestroy
-  static removeFile (instance: VideoRedundancyModel) {
+  @BeforeDestroy
+  static async removeFile (instance: VideoRedundancyModel) {
     // Not us
     if (!instance.strategy) return
 
-    logger.info('Removing duplicated video file %s-%s.', instance.VideoFile.Video.uuid, instance.VideoFile.resolution)
+    const videoFile = await VideoFileModel.loadWithVideo(instance.videoFileId)
 
-    return instance.VideoFile.Video.removeFile(instance.VideoFile)
+    logger.info('Removing duplicated video file %s-%s.', videoFile.Video.uuid, videoFile.resolution)
+
+    return videoFile.Video.removeFile(videoFile)
   }
 
   static async loadLocalByFileId (videoFileId: number) {