diff options
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/video-streaming-playlist.ts | 12 | ||||
-rw-r--r-- | server/models/video/video.ts | 30 |
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' | |||
17 | import { sha1 } from '../../helpers/core-utils' | 17 | import { sha1 } from '../../helpers/core-utils' |
18 | import { isArrayOf } from '../../helpers/custom-validators/misc' | 18 | import { isArrayOf } from '../../helpers/custom-validators/misc' |
19 | import { Op, QueryTypes } from 'sequelize' | 19 | import { Op, QueryTypes } from 'sequelize' |
20 | import { MStreamingPlaylist, MVideoFile } from '@server/typings/models' | 20 | import { MStreamingPlaylist, MStreamingPlaylistVideo, MVideoFile } from '@server/typings/models' |
21 | import { VideoFileModel } from '@server/models/video/video-file' | 21 | import { VideoFileModel } from '@server/models/video/video-file' |
22 | import { getTorrentFileName, getVideoFilename } from '@server/lib/video-paths' | 22 | import { getTorrentFileName, getTorrentFilePath, getVideoFilename } from '@server/lib/video-paths' |
23 | import * as memoizee from 'memoizee' | 23 | import * as memoizee from 'memoizee' |
24 | import { remove } from 'fs-extra' | ||
25 | import { 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' |
141 | import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../typings/models/video/video-file' | 142 | import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../typings/models/video/video-file' |
142 | import { MThumbnail } from '../../typings/models/video/thumbnail' | 143 | import { 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 () { |