aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/redundancy/video-redundancy.ts2
-rw-r--r--server/models/video/video-streaming-playlist.ts12
-rw-r--r--server/models/video/video.ts30
3 files changed, 36 insertions, 8 deletions
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts
index 77f83d8aa..8c9a7eabf 100644
--- a/server/models/redundancy/video-redundancy.ts
+++ b/server/models/redundancy/video-redundancy.ts
@@ -160,7 +160,7 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
160 const videoUUID = videoStreamingPlaylist.Video.uuid 160 const videoUUID = videoStreamingPlaylist.Video.uuid
161 logger.info('Removing duplicated video streaming playlist %s.', videoUUID) 161 logger.info('Removing duplicated video streaming playlist %s.', videoUUID)
162 162
163 videoStreamingPlaylist.Video.removeStreamingPlaylist(true) 163 videoStreamingPlaylist.Video.removeStreamingPlaylistFiles(videoStreamingPlaylist, true)
164 .catch(err => logger.error('Cannot delete video streaming playlist files of %s.', videoUUID, { err })) 164 .catch(err => logger.error('Cannot delete video streaming playlist files of %s.', videoUUID, { err }))
165 } 165 }
166 166
diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts
index 0099add4e..249596218 100644
--- a/server/models/video/video-streaming-playlist.ts
+++ b/server/models/video/video-streaming-playlist.ts
@@ -17,10 +17,12 @@ import { join } from 'path'
17import { sha1 } from '../../helpers/core-utils' 17import { sha1 } from '../../helpers/core-utils'
18import { isArrayOf } from '../../helpers/custom-validators/misc' 18import { isArrayOf } from '../../helpers/custom-validators/misc'
19import { Op, QueryTypes } from 'sequelize' 19import { Op, QueryTypes } from 'sequelize'
20import { MStreamingPlaylist, MVideoFile } from '@server/typings/models' 20import { MStreamingPlaylist, MStreamingPlaylistVideo, MVideoFile } from '@server/typings/models'
21import { VideoFileModel } from '@server/models/video/video-file' 21import { VideoFileModel } from '@server/models/video/video-file'
22import { getTorrentFileName, getVideoFilename } from '@server/lib/video-paths' 22import { getTorrentFileName, getTorrentFilePath, getVideoFilename } from '@server/lib/video-paths'
23import * as memoizee from 'memoizee' 23import * as memoizee from 'memoizee'
24import { remove } from 'fs-extra'
25import { logger } from '@server/helpers/logger'
24 26
25@Table({ 27@Table({
26 tableName: 'videoStreamingPlaylist', 28 tableName: 'videoStreamingPlaylist',
@@ -209,4 +211,10 @@ export class VideoStreamingPlaylistModel extends Model<VideoStreamingPlaylistMod
209 return this.type === other.type && 211 return this.type === other.type &&
210 this.videoId === other.videoId 212 this.videoId === other.videoId
211 } 213 }
214
215 removeTorrent (this: MStreamingPlaylistVideo, videoFile: MVideoFile) {
216 const torrentPath = getTorrentFilePath(this, videoFile)
217 return remove(torrentPath)
218 .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err }))
219 }
212} 220}
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 243871028..eacffe186 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -136,7 +136,8 @@ import {
136 MVideoThumbnailBlacklist, 136 MVideoThumbnailBlacklist,
137 MVideoWithAllFiles, 137 MVideoWithAllFiles,
138 MVideoWithFile, 138 MVideoWithFile,
139 MVideoWithRights 139 MVideoWithRights,
140 MStreamingPlaylistFiles
140} from '../../typings/models' 141} from '../../typings/models'
141import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../typings/models/video/video-file' 142import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../typings/models/video/video-file'
142import { MThumbnail } from '../../typings/models/video/thumbnail' 143import { MThumbnail } from '../../typings/models/video/thumbnail'
@@ -1071,7 +1072,13 @@ export class VideoModel extends Model<VideoModel> {
1071 }) 1072 })
1072 1073
1073 // Remove playlists file 1074 // Remove playlists file
1074 tasks.push(instance.removeStreamingPlaylist()) 1075 if (!Array.isArray(instance.VideoStreamingPlaylists)) {
1076 instance.VideoStreamingPlaylists = await instance.$get('VideoStreamingPlaylists')
1077 }
1078
1079 for (const p of instance.VideoStreamingPlaylists) {
1080 tasks.push(instance.removeStreamingPlaylistFiles(p))
1081 }
1075 } 1082 }
1076 1083
1077 // Do not wait video deletion because we could be in a transaction 1084 // Do not wait video deletion because we could be in a transaction
@@ -2001,11 +2008,24 @@ export class VideoModel extends Model<VideoModel> {
2001 .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err })) 2008 .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err }))
2002 } 2009 }
2003 2010
2004 removeStreamingPlaylist (isRedundancy = false) { 2011 async removeStreamingPlaylistFiles (streamingPlaylist: MStreamingPlaylist, isRedundancy = false) {
2005 const directoryPath = getHLSDirectory(this, isRedundancy) 2012 const directoryPath = getHLSDirectory(this, isRedundancy)
2006 2013
2007 return remove(directoryPath) 2014 await remove(directoryPath)
2008 .catch(err => logger.warn('Cannot delete playlist directory %s.', directoryPath, { err })) 2015
2016 if (isRedundancy !== true) {
2017 let streamingPlaylistWithFiles = streamingPlaylist as MStreamingPlaylistFilesVideo
2018 streamingPlaylistWithFiles.Video = this
2019
2020 if (!Array.isArray(streamingPlaylistWithFiles.VideoFiles)) {
2021 streamingPlaylistWithFiles.VideoFiles = await streamingPlaylistWithFiles.$get('VideoFiles')
2022 }
2023
2024 // Remove physical files and torrents
2025 await Promise.all(
2026 streamingPlaylistWithFiles.VideoFiles.map(file => streamingPlaylistWithFiles.removeTorrent(file))
2027 )
2028 }
2009 } 2029 }
2010 2030
2011 isOutdated () { 2031 isOutdated () {