]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/redundancy/video-redundancy.ts
Fix redundancy with videos already duplicated with another instance
[github/Chocobozzz/PeerTube.git] / server / models / redundancy / video-redundancy.ts
index e6716480280c32f1ce89faf44f360f8fee62ee80..c23a9cc17f26417b57c8dd870ee9f6e3d3bfe99c 100644 (file)
@@ -125,9 +125,12 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
     return instance.VideoFile.Video.removeFile(instance.VideoFile)
   }
 
-  static loadByFileId (videoFileId: number) {
+  static async loadLocalByFileId (videoFileId: number) {
+    const actor = await getServerActor()
+
     const query = {
       where: {
+        actorId: actor.id,
         videoFileId
       }
     }
@@ -146,6 +149,38 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
     return VideoRedundancyModel.findOne(query)
   }
 
+  static async isLocalByVideoUUIDExists (uuid: string) {
+    const actor = await getServerActor()
+
+    const query = {
+      raw: true,
+      attributes: [ 'id' ],
+      where: {
+        actorId: actor.id
+      },
+      include: [
+        {
+          attributes: [ ],
+          model: VideoFileModel,
+          required: true,
+          include: [
+            {
+              attributes: [ ],
+              model: VideoModel,
+              required: true,
+              where: {
+                uuid
+              }
+            }
+          ]
+        }
+      ]
+    }
+
+    return VideoRedundancyModel.findOne(query)
+      .then(r => !!r)
+  }
+
   static async getVideoSample (p: Bluebird<VideoModel[]>) {
     const rows = await p
     const ids = rows.map(r => r.id)