]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/redundancy/video-redundancy.ts
Ensure we don't run transcoding after import file
[github/Chocobozzz/PeerTube.git] / server / models / redundancy / video-redundancy.ts
index ca56a57dc67bb1cba0c8ce2afc23401fd914a09c..e8d79a3ab23dc218a5795751a22c76cdb72ee5eb 100644 (file)
@@ -79,6 +79,9 @@ export enum ScopeNames {
     {
       fields: [ 'actorId' ]
     },
+    {
+      fields: [ 'expiresOn' ]
+    },
     {
       fields: [ 'url' ],
       unique: true
@@ -157,8 +160,8 @@ export class VideoRedundancyModel extends Model<Partial<AttributesOnly<VideoRedu
       const logIdentifier = `${videoFile.Video.uuid}-${videoFile.resolution}`
       logger.info('Removing duplicated video file %s.', logIdentifier)
 
-      videoFile.Video.removeFile(videoFile, true)
-               .catch(err => logger.error('Cannot delete %s files.', logIdentifier, { err }))
+      videoFile.Video.removeWebTorrentFileAndTorrent(videoFile, true)
+        .catch(err => logger.error('Cannot delete %s files.', logIdentifier, { err }))
     }
 
     if (instance.videoStreamingPlaylistId) {
@@ -408,7 +411,7 @@ export class VideoRedundancyModel extends Model<Partial<AttributesOnly<VideoRedu
     return VideoRedundancyModel.scope([ ScopeNames.WITH_VIDEO ]).findOne(query)
   }
 
-  static async listLocalExpired () {
+  static async listLocalExpired (): Promise<MVideoRedundancyVideo[]> {
     const actor = await getServerActor()
 
     const query = {
@@ -467,16 +470,34 @@ export class VideoRedundancyModel extends Model<Partial<AttributesOnly<VideoRedu
 
     const query = {
       where: {
-        actorId: actor.id
+        [Op.and]: [
+          {
+            actorId: actor.id
+          },
+          {
+            [Op.or]: [
+              {
+                '$VideoStreamingPlaylist.id$': {
+                  [Op.ne]: null
+                }
+              },
+              {
+                '$VideoFile.id$': {
+                  [Op.ne]: null
+                }
+              }
+            ]
+          }
+        ]
       },
       include: [
         {
-          model: VideoFileModel,
+          model: VideoFileModel.unscoped(),
           required: false,
           include: [ buildVideoInclude() ]
         },
         {
-          model: VideoStreamingPlaylistModel,
+          model: VideoStreamingPlaylistModel.unscoped(),
           required: false,
           include: [ buildVideoInclude() ]
         }
@@ -680,6 +701,13 @@ export class VideoRedundancyModel extends Model<Partial<AttributesOnly<VideoRedu
     return undefined
   }
 
+  getVideoUUID () {
+    const video = this.getVideo()
+    if (!video) return undefined
+
+    return video.uuid
+  }
+
   isOwned () {
     return !!this.strategy
   }