aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--client/package.json4
-rw-r--r--package.json4
-rw-r--r--server/models/redundancy/video-redundancy.ts12
-rw-r--r--server/models/video/video-file.ts13
-rw-r--r--server/tests/api/server/redundancy.ts19
-rw-r--r--server/tests/utils/videos/videos.ts8
6 files changed, 48 insertions, 12 deletions
diff --git a/client/package.json b/client/package.json
index 3c1c6976a..76a4eedad 100644
--- a/client/package.json
+++ b/client/package.json
@@ -4,8 +4,8 @@
4 "private": true, 4 "private": true,
5 "licence": "GPLv3", 5 "licence": "GPLv3",
6 "author": { 6 "author": {
7 "name": "Florian Bigard", 7 "name": "Chocobozzz",
8 "email": "me@florianbigard.com", 8 "email": "chocobozzz@cpy.re",
9 "url": "http://github.com/Chocobozzz" 9 "url": "http://github.com/Chocobozzz"
10 }, 10 },
11 "repository": { 11 "repository": {
diff --git a/package.json b/package.json
index 366fae840..80d5a04ac 100644
--- a/package.json
+++ b/package.json
@@ -11,8 +11,8 @@
11 "peertube": "dist/server/tools/peertube.js" 11 "peertube": "dist/server/tools/peertube.js"
12 }, 12 },
13 "author": { 13 "author": {
14 "name": "Florian Bigard", 14 "name": "Chocobozzz",
15 "email": "florian.bigard@gmail.com", 15 "email": "chocobozzz@cpy.re",
16 "url": "http://github.com/Chocobozzz" 16 "url": "http://github.com/Chocobozzz"
17 }, 17 },
18 "repository": { 18 "repository": {
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts
index c23a9cc17..da1c6f4a7 100644
--- a/server/models/redundancy/video-redundancy.ts
+++ b/server/models/redundancy/video-redundancy.ts
@@ -1,6 +1,6 @@
1import { 1import {
2 AfterDestroy,
3 AllowNull, 2 AllowNull,
3 BeforeDestroy,
4 BelongsTo, 4 BelongsTo,
5 Column, 5 Column,
6 CreatedAt, 6 CreatedAt,
@@ -115,14 +115,16 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
115 }) 115 })
116 Actor: ActorModel 116 Actor: ActorModel
117 117
118 @AfterDestroy 118 @BeforeDestroy
119 static removeFile (instance: VideoRedundancyModel) { 119 static async removeFile (instance: VideoRedundancyModel) {
120 // Not us 120 // Not us
121 if (!instance.strategy) return 121 if (!instance.strategy) return
122 122
123 logger.info('Removing duplicated video file %s-%s.', instance.VideoFile.Video.uuid, instance.VideoFile.resolution) 123 const videoFile = await VideoFileModel.loadWithVideo(instance.videoFileId)
124 124
125 return instance.VideoFile.Video.removeFile(instance.VideoFile) 125 logger.info('Removing duplicated video file %s-%s.', videoFile.Video.uuid, videoFile.resolution)
126
127 return videoFile.Video.removeFile(videoFile)
126 } 128 }
127 129
128 static async loadLocalByFileId (videoFileId: number) { 130 static async loadLocalByFileId (videoFileId: number) {
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts
index f040803b9..adebdf0c7 100644
--- a/server/models/video/video-file.ts
+++ b/server/models/video/video-file.ts
@@ -107,6 +107,19 @@ export class VideoFileModel extends Model<VideoFileModel> {
107 }) 107 })
108 } 108 }
109 109
110 static loadWithVideo (id: number) {
111 const options = {
112 include: [
113 {
114 model: VideoModel.unscoped(),
115 required: true
116 }
117 ]
118 }
119
120 return VideoFileModel.findById(id, options)
121 }
122
110 hasSameUniqueKeysThan (other: VideoFileModel) { 123 hasSameUniqueKeysThan (other: VideoFileModel) {
111 return this.fps === other.fps && 124 return this.fps === other.fps &&
112 this.resolution === other.resolution && 125 this.resolution === other.resolution &&
diff --git a/server/tests/api/server/redundancy.ts b/server/tests/api/server/redundancy.ts
index d60319657..1960854b6 100644
--- a/server/tests/api/server/redundancy.ts
+++ b/server/tests/api/server/redundancy.ts
@@ -16,7 +16,8 @@ import {
16 uploadVideo, 16 uploadVideo,
17 viewVideo, 17 viewVideo,
18 wait, 18 wait,
19 waitUntilLog 19 waitUntilLog,
20 checkVideoFilesWereRemoved, removeVideo
20} from '../../utils' 21} from '../../utils'
21import { waitJobs } from '../../utils/server/jobs' 22import { waitJobs } from '../../utils/server/jobs'
22import * as magnetUtil from 'magnet-uri' 23import * as magnetUtil from 'magnet-uri'
@@ -242,6 +243,8 @@ describe('Test videos redundancy', function () {
242 await wait(5000) 243 await wait(5000)
243 244
244 await check1WebSeed(strategy) 245 await check1WebSeed(strategy)
246
247 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ])
245 }) 248 })
246 249
247 after(function () { 250 after(function () {
@@ -287,6 +290,8 @@ describe('Test videos redundancy', function () {
287 await wait(5000) 290 await wait(5000)
288 291
289 await check1WebSeed(strategy) 292 await check1WebSeed(strategy)
293
294 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ])
290 }) 295 })
291 296
292 after(function () { 297 after(function () {
@@ -344,6 +349,18 @@ describe('Test videos redundancy', function () {
344 await checkStatsWith2Webseed(strategy) 349 await checkStatsWith2Webseed(strategy)
345 }) 350 })
346 351
352 it('Should remove the video and the redundancy files', async function () {
353 this.timeout(20000)
354
355 await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID)
356
357 await waitJobs(servers)
358
359 for (const server of servers) {
360 await checkVideoFilesWereRemoved(video1Server2UUID, server.serverNumber)
361 }
362 })
363
347 after(function () { 364 after(function () {
348 return cleanServers() 365 return cleanServers()
349 }) 366 })
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts
index 7eee25402..87c385f38 100644
--- a/server/tests/utils/videos/videos.ts
+++ b/server/tests/utils/videos/videos.ts
@@ -267,10 +267,14 @@ function removeVideo (url: string, token: string, id: number | string, expectedS
267 .expect(expectedStatus) 267 .expect(expectedStatus)
268} 268}
269 269
270async function checkVideoFilesWereRemoved (videoUUID: string, serverNumber: number) { 270async function checkVideoFilesWereRemoved (
271 videoUUID: string,
272 serverNumber: number,
273 directories = [ 'videos', 'thumbnails', 'torrents', 'previews', 'captions' ]
274) {
271 const testDirectory = 'test' + serverNumber 275 const testDirectory = 'test' + serverNumber
272 276
273 for (const directory of [ 'videos', 'thumbnails', 'torrents', 'previews', 'captions' ]) { 277 for (const directory of directories) {
274 const directoryPath = join(root(), testDirectory, directory) 278 const directoryPath = join(root(), testDirectory, directory)
275 279
276 const directoryExists = existsSync(directoryPath) 280 const directoryExists = existsSync(directoryPath)