]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/redundancy/video-redundancy.ts
Fix AP collections pagination
[github/Chocobozzz/PeerTube.git] / server / models / redundancy / video-redundancy.ts
index 2ebe23ef163533d638fc74dfa8ec0613fb95cdf4..9de4356b408c45961ea52e7087969c984f1dca3a 100644 (file)
@@ -117,8 +117,7 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
 
   @BeforeDestroy
   static async removeFile (instance: VideoRedundancyModel) {
-    // Not us
-    if (!instance.strategy) return
+    if (!instance.isOwned()) return
 
     const videoFile = await VideoFileModel.loadWithVideo(instance.videoFileId)
 
@@ -293,6 +292,11 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
     }
 
     return VideoFileModel.sum('size', options as any) // FIXME: typings
+      .then(v => {
+        if (!v || isNaN(v)) return 0
+
+        return v
+      })
   }
 
   static async listLocalExpired () {
@@ -399,6 +403,10 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
       }))
   }
 
+  isOwned () {
+    return !!this.strategy
+  }
+
   toActivityPubObject (): CacheFileObject {
     return {
       id: this.url,
@@ -408,6 +416,7 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
       url: {
         type: 'Link',
         mimeType: VIDEO_EXT_MIMETYPE[ this.VideoFile.extname ] as any,
+        mediaType: VIDEO_EXT_MIMETYPE[ this.VideoFile.extname ] as any,
         href: this.fileUrl,
         height: this.VideoFile.resolution,
         size: this.VideoFile.size,