From 25378bc866a69002d7447e5edc254ec7e469a1ec Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 3 Oct 2018 16:43:57 +0200 Subject: [PATCH] Delete correctly redundancy files --- client/package.json | 4 ++-- package.json | 4 ++-- server/models/redundancy/video-redundancy.ts | 12 +++++++----- server/models/video/video-file.ts | 13 +++++++++++++ server/tests/api/server/redundancy.ts | 19 ++++++++++++++++++- server/tests/utils/videos/videos.ts | 8 ++++++-- 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 @@ "private": true, "licence": "GPLv3", "author": { - "name": "Florian Bigard", - "email": "me@florianbigard.com", + "name": "Chocobozzz", + "email": "chocobozzz@cpy.re", "url": "http://github.com/Chocobozzz" }, "repository": { diff --git a/package.json b/package.json index 366fae840..80d5a04ac 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "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": { 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 @@ import { - AfterDestroy, AllowNull, + BeforeDestroy, BelongsTo, Column, CreatedAt, @@ -115,14 +115,16 @@ export class VideoRedundancyModel extends Model { }) Actor: ActorModel - @AfterDestroy - static removeFile (instance: VideoRedundancyModel) { + @BeforeDestroy + static async removeFile (instance: VideoRedundancyModel) { // 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) { 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 { }) } + 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 && 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 { uploadVideo, viewVideo, wait, - waitUntilLog + waitUntilLog, + checkVideoFilesWereRemoved, removeVideo } 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 checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ]) }) after(function () { @@ -287,6 +290,8 @@ describe('Test videos redundancy', function () { await wait(5000) await check1WebSeed(strategy) + + await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ]) }) after(function () { @@ -344,6 +349,18 @@ describe('Test videos redundancy', function () { 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() }) 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 .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 - for (const directory of [ 'videos', 'thumbnails', 'torrents', 'previews', 'captions' ]) { + for (const directory of directories) { const directoryPath = join(root(), testDirectory, directory) const directoryExists = existsSync(directoryPath) -- 2.41.0