From 25378bc866a69002d7447e5edc254ec7e469a1ec Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 3 Oct 2018 16:43:57 +0200 Subject: Delete correctly redundancy files --- server/models/redundancy/video-redundancy.ts | 12 +++++++----- server/models/video/video-file.ts | 13 +++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'server/models') 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 && -- cgit v1.2.3