]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Delete correctly redundancy files
authorChocobozzz <me@florianbigard.com>
Wed, 3 Oct 2018 14:43:57 +0000 (16:43 +0200)
committerChocobozzz <me@florianbigard.com>
Wed, 3 Oct 2018 14:43:57 +0000 (16:43 +0200)
client/package.json
package.json
server/models/redundancy/video-redundancy.ts
server/models/video/video-file.ts
server/tests/api/server/redundancy.ts
server/tests/utils/videos/videos.ts

index 3c1c6976a49045c99e71922eba821dc5f6161d3e..76a4eedad588adcdd41f7ecd764e896b05141232 100644 (file)
@@ -4,8 +4,8 @@
   "private": true,
   "licence": "GPLv3",
   "author": {
   "private": true,
   "licence": "GPLv3",
   "author": {
-    "name": "Florian Bigard",
-    "email": "me@florianbigard.com",
+    "name": "Chocobozzz",
+    "email": "chocobozzz@cpy.re",
     "url": "http://github.com/Chocobozzz"
   },
   "repository": {
     "url": "http://github.com/Chocobozzz"
   },
   "repository": {
index 366fae8402bd701e0f9f03c17c5984c6f28117f2..80d5a04acfb45847f75a1d3043096c68254c2b2e 100644 (file)
@@ -11,8 +11,8 @@
     "peertube": "dist/server/tools/peertube.js"
   },
   "author": {
     "peertube": "dist/server/tools/peertube.js"
   },
   "author": {
-    "name": "Florian Bigard",
-    "email": "florian.bigard@gmail.com",
+    "name": "Chocobozzz",
+    "email": "chocobozzz@cpy.re",
     "url": "http://github.com/Chocobozzz"
   },
   "repository": {
     "url": "http://github.com/Chocobozzz"
   },
   "repository": {
index c23a9cc17f26417b57c8dd870ee9f6e3d3bfe99c..da1c6f4a7f11d844e5047049e44aecdffd538f10 100644 (file)
@@ -1,6 +1,6 @@
 import {
 import {
-  AfterDestroy,
   AllowNull,
   AllowNull,
+  BeforeDestroy,
   BelongsTo,
   Column,
   CreatedAt,
   BelongsTo,
   Column,
   CreatedAt,
@@ -115,14 +115,16 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
   })
   Actor: ActorModel
 
   })
   Actor: ActorModel
 
-  @AfterDestroy
-  static removeFile (instance: VideoRedundancyModel) {
+  @BeforeDestroy
+  static async removeFile (instance: VideoRedundancyModel) {
     // Not us
     if (!instance.strategy) return
 
     // 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) {
   }
 
   static async loadLocalByFileId (videoFileId: number) {
index f040803b9a0240d2156df0dc073e0609f237b3fe..adebdf0c75f61ba99436b08631f2d3a90612f458 100644 (file)
@@ -107,6 +107,19 @@ export class VideoFileModel extends Model<VideoFileModel> {
               })
   }
 
               })
   }
 
+  static loadWithVideo (id: number) {
+    const options = {
+      include: [
+        {
+          model: VideoModel.unscoped(),
+          required: true
+        }
+      ]
+    }
+
+    return VideoFileModel.findById(id, options)
+  }
+
   hasSameUniqueKeysThan (other: VideoFileModel) {
     return this.fps === other.fps &&
       this.resolution === other.resolution &&
   hasSameUniqueKeysThan (other: VideoFileModel) {
     return this.fps === other.fps &&
       this.resolution === other.resolution &&
index d6031965757155972fc6ffc36842b9a5fd0a943d..1960854b654136e5d5b40818c7aa5490a40f95a7 100644 (file)
@@ -16,7 +16,8 @@ import {
   uploadVideo,
   viewVideo,
   wait,
   uploadVideo,
   viewVideo,
   wait,
-  waitUntilLog
+  waitUntilLog,
+  checkVideoFilesWereRemoved, removeVideo
 } from '../../utils'
 import { waitJobs } from '../../utils/server/jobs'
 import * as magnetUtil from 'magnet-uri'
 } from '../../utils'
 import { waitJobs } from '../../utils/server/jobs'
 import * as magnetUtil from 'magnet-uri'
@@ -242,6 +243,8 @@ describe('Test videos redundancy', function () {
       await wait(5000)
 
       await check1WebSeed(strategy)
       await wait(5000)
 
       await check1WebSeed(strategy)
+
+      await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ])
     })
 
     after(function () {
     })
 
     after(function () {
@@ -287,6 +290,8 @@ describe('Test videos redundancy', function () {
       await wait(5000)
 
       await check1WebSeed(strategy)
       await wait(5000)
 
       await check1WebSeed(strategy)
+
+      await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ])
     })
 
     after(function () {
     })
 
     after(function () {
@@ -344,6 +349,18 @@ describe('Test videos redundancy', function () {
       await checkStatsWith2Webseed(strategy)
     })
 
       await checkStatsWith2Webseed(strategy)
     })
 
+    it('Should remove the video and the redundancy files', async function () {
+      this.timeout(20000)
+
+      await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID)
+
+      await waitJobs(servers)
+
+      for (const server of servers) {
+        await checkVideoFilesWereRemoved(video1Server2UUID, server.serverNumber)
+      }
+    })
+
     after(function () {
       return cleanServers()
     })
     after(function () {
       return cleanServers()
     })
index 7eee254026452e47042cc12c8ed236f2a17aa6fb..87c385f3877f87109c23e21f187a87fc0c793b4a 100644 (file)
@@ -267,10 +267,14 @@ function removeVideo (url: string, token: string, id: number | string, expectedS
           .expect(expectedStatus)
 }
 
           .expect(expectedStatus)
 }
 
-async function checkVideoFilesWereRemoved (videoUUID: string, serverNumber: number) {
+async function checkVideoFilesWereRemoved (
+  videoUUID: string,
+  serverNumber: number,
+  directories = [ 'videos', 'thumbnails', 'torrents', 'previews', 'captions' ]
+) {
   const testDirectory = 'test' + serverNumber
 
   const testDirectory = 'test' + serverNumber
 
-  for (const directory of [ 'videos', 'thumbnails', 'torrents', 'previews', 'captions' ]) {
+  for (const directory of directories) {
     const directoryPath = join(root(), testDirectory, directory)
 
     const directoryExists = existsSync(directoryPath)
     const directoryPath = join(root(), testDirectory, directory)
 
     const directoryExists = existsSync(directoryPath)