aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-01-24 16:48:05 +0100
committerChocobozzz <me@florianbigard.com>2020-01-24 16:48:05 +0100
commitffc65cbd2a3d8b0b41243baec9936272592137e3 (patch)
tree1d48a71e08d9213683aa6650d69645c676afeb6a /server/models/video
parentb40eed8b09336ce3a64a0cc99a467e487ce0ef94 (diff)
downloadPeerTube-ffc65cbd2a3d8b0b41243baec9936272592137e3.tar.gz
PeerTube-ffc65cbd2a3d8b0b41243baec9936272592137e3.tar.zst
PeerTube-ffc65cbd2a3d8b0b41243baec9936272592137e3.zip
Remove HLS torrents
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-streaming-playlist.ts12
-rw-r--r--server/models/video/video.ts30
2 files changed, 35 insertions, 7 deletions
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 () {