diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/redundancy/video-redundancy.ts | 12 | ||||
-rw-r--r-- | server/models/video/video-file.ts | 13 |
2 files changed, 20 insertions, 5 deletions
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 @@ | |||
1 | import { | 1 | import { |
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 && |