const videoUUID = videoStreamingPlaylist.Video.uuid
logger.info('Removing duplicated video streaming playlist %s.', videoUUID)
- videoStreamingPlaylist.Video.removeStreamingPlaylist(true)
+ videoStreamingPlaylist.Video.removeStreamingPlaylistFiles(videoStreamingPlaylist, true)
.catch(err => logger.error('Cannot delete video streaming playlist files of %s.', videoUUID, { err }))
}
import { sha1 } from '../../helpers/core-utils'
import { isArrayOf } from '../../helpers/custom-validators/misc'
import { Op, QueryTypes } from 'sequelize'
-import { MStreamingPlaylist, MVideoFile } from '@server/typings/models'
+import { MStreamingPlaylist, MStreamingPlaylistVideo, MVideoFile } from '@server/typings/models'
import { VideoFileModel } from '@server/models/video/video-file'
-import { getTorrentFileName, getVideoFilename } from '@server/lib/video-paths'
+import { getTorrentFileName, getTorrentFilePath, getVideoFilename } from '@server/lib/video-paths'
import * as memoizee from 'memoizee'
+import { remove } from 'fs-extra'
+import { logger } from '@server/helpers/logger'
@Table({
tableName: 'videoStreamingPlaylist',
return this.type === other.type &&
this.videoId === other.videoId
}
+
+ removeTorrent (this: MStreamingPlaylistVideo, videoFile: MVideoFile) {
+ const torrentPath = getTorrentFilePath(this, videoFile)
+ return remove(torrentPath)
+ .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err }))
+ }
}
MVideoThumbnailBlacklist,
MVideoWithAllFiles,
MVideoWithFile,
- MVideoWithRights
+ MVideoWithRights,
+ MStreamingPlaylistFiles
} from '../../typings/models'
import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../typings/models/video/video-file'
import { MThumbnail } from '../../typings/models/video/thumbnail'
})
// Remove playlists file
- tasks.push(instance.removeStreamingPlaylist())
+ if (!Array.isArray(instance.VideoStreamingPlaylists)) {
+ instance.VideoStreamingPlaylists = await instance.$get('VideoStreamingPlaylists')
+ }
+
+ for (const p of instance.VideoStreamingPlaylists) {
+ tasks.push(instance.removeStreamingPlaylistFiles(p))
+ }
}
// Do not wait video deletion because we could be in a transaction
.catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err }))
}
- removeStreamingPlaylist (isRedundancy = false) {
+ async removeStreamingPlaylistFiles (streamingPlaylist: MStreamingPlaylist, isRedundancy = false) {
const directoryPath = getHLSDirectory(this, isRedundancy)
- return remove(directoryPath)
- .catch(err => logger.warn('Cannot delete playlist directory %s.', directoryPath, { err }))
+ await remove(directoryPath)
+
+ if (isRedundancy !== true) {
+ let streamingPlaylistWithFiles = streamingPlaylist as MStreamingPlaylistFilesVideo
+ streamingPlaylistWithFiles.Video = this
+
+ if (!Array.isArray(streamingPlaylistWithFiles.VideoFiles)) {
+ streamingPlaylistWithFiles.VideoFiles = await streamingPlaylistWithFiles.$get('VideoFiles')
+ }
+
+ // Remove physical files and torrents
+ await Promise.all(
+ streamingPlaylistWithFiles.VideoFiles.map(file => streamingPlaylistWithFiles.removeTorrent(file))
+ )
+ }
}
isOutdated () {
await check1WebSeed()
await check0PlaylistRedundancies()
- await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos', join('playlists', 'hls') ])
+ await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ 'videos', join('playlists', 'hls') ])
})
after(async function () {
await check1WebSeed()
await check0PlaylistRedundancies()
- await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ])
+ await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ 'videos' ])
})
after(async function () {
await waitJobs(servers)
for (const server of servers) {
- await checkVideoFilesWereRemoved(video1Server2UUID, server.serverNumber)
+ await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber)
}
})
await waitJobs(servers)
- await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ join('redundancy', 'hls') ])
+ await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ join('redundancy', 'hls') ])
})
after(async function () {
createUser,
dateIsValid,
doubleFollow,
- flushAndRunServer,
flushAndRunMultipleServers,
getLocalVideos,
getVideo,
it('Should not have files of videos 3 and 3-2 on each server', async function () {
for (const server of servers) {
- await checkVideoFilesWereRemoved(toRemove[0].uuid, server.serverNumber)
- await checkVideoFilesWereRemoved(toRemove[1].uuid, server.serverNumber)
+ await checkVideoFilesWereRemoved(toRemove[0].uuid, server.internalServerNumber)
+ await checkVideoFilesWereRemoved(toRemove[1].uuid, server.internalServerNumber)
}
})
function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) {
return new Promise<any>((res, rej) => {
const torrentName = videoUUID + '-' + resolution + '.torrent'
- const torrentPath = join(root(), 'test' + server.serverNumber, 'torrents', torrentName)
+ const torrentPath = join(root(), 'test' + server.internalServerNumber, 'torrents', torrentName)
readFile(torrentPath, (err, data) => {
if (err) return rej(err)