]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/redundancy/video-redundancy.ts
Support studio transcoding in peertube runner
[github/Chocobozzz/PeerTube.git] / server / models / redundancy / video-redundancy.ts
index f7a989691d83e201909bbb7fb887e8e275393135..c2a72b71f42d554bae801ca1e106f88a741d2bd8 100644 (file)
@@ -1,5 +1,5 @@
 import { sample } from 'lodash'
-import { FindOptions, literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize'
+import { literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize'
 import {
   AllowNull,
   BeforeDestroy,
@@ -16,15 +16,17 @@ import {
 } from 'sequelize-typescript'
 import { getServerActor } from '@server/models/application/application'
 import { MActor, MVideoForRedundancyAPI, MVideoRedundancy, MVideoRedundancyAP, MVideoRedundancyVideo } from '@server/types/models'
-import { AttributesOnly } from '@shared/core-utils'
-import { VideoRedundanciesTarget } from '@shared/models/redundancy/video-redundancies-filters.model'
 import {
+  CacheFileObject,
   FileRedundancyInformation,
   StreamingPlaylistRedundancyInformation,
-  VideoRedundancy
-} from '@shared/models/redundancy/video-redundancy.model'
-import { CacheFileObject, VideoPrivacy } from '../../../shared'
-import { VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../shared/models/redundancy'
+  VideoPrivacy,
+  VideoRedundanciesTarget,
+  VideoRedundancy,
+  VideoRedundancyStrategy,
+  VideoRedundancyStrategyWithManual
+} from '@shared/models'
+import { AttributesOnly } from '@shared/typescript-utils'
 import { isTestInstance } from '../../helpers/core-utils'
 import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validators/activitypub/misc'
 import { logger } from '../../helpers/logger'
@@ -32,7 +34,7 @@ import { CONFIG } from '../../initializers/config'
 import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../initializers/constants'
 import { ActorModel } from '../actor/actor'
 import { ServerModel } from '../server/server'
-import { getSort, getVideoSort, parseAggregateResult, throwIfNotValid } from '../utils'
+import { getSort, getVideoSort, parseAggregateResult, throwIfNotValid } from '../shared'
 import { ScheduleVideoUpdateModel } from '../video/schedule-video-update'
 import { VideoModel } from '../video/video'
 import { VideoChannelModel } from '../video/video-channel'
@@ -79,6 +81,9 @@ export enum ScopeNames {
     {
       fields: [ 'actorId' ]
     },
+    {
+      fields: [ 'expiresOn' ]
+    },
     {
       fields: [ 'url' ],
       unique: true
@@ -157,8 +162,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.removeWebTorrentFile(videoFile, true)
+        .catch(err => logger.error('Cannot delete %s files.', logIdentifier, { err }))
     }
 
     if (instance.videoStreamingPlaylistId) {
@@ -408,7 +413,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 +472,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() ]
         }
@@ -507,7 +530,7 @@ export class VideoRedundancyModel extends Model<Partial<AttributesOnly<VideoRedu
     }
 
     if (strategy) {
-      Object.assign(redundancyWhere, { strategy: strategy })
+      Object.assign(redundancyWhere, { strategy })
     }
 
     const videoFilterWhere = {
@@ -680,6 +703,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
   }