aboutsummaryrefslogtreecommitdiffhomepage
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
parentb40eed8b09336ce3a64a0cc99a467e487ce0ef94 (diff)
downloadPeerTube-ffc65cbd2a3d8b0b41243baec9936272592137e3.tar.gz
PeerTube-ffc65cbd2a3d8b0b41243baec9936272592137e3.tar.zst
PeerTube-ffc65cbd2a3d8b0b41243baec9936272592137e3.zip
Remove HLS torrents
-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
-rw-r--r--server/tests/api/redundancy/redundancy.ts8
-rw-r--r--server/tests/api/videos/multiple-servers.ts5
-rw-r--r--shared/extra-utils/videos/videos.ts2
6 files changed, 43 insertions, 16 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 () {
diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts
index be24eb32f..1cdf93aa1 100644
--- a/server/tests/api/redundancy/redundancy.ts
+++ b/server/tests/api/redundancy/redundancy.ts
@@ -318,7 +318,7 @@ describe('Test videos redundancy', function () {
318 await check1WebSeed() 318 await check1WebSeed()
319 await check0PlaylistRedundancies() 319 await check0PlaylistRedundancies()
320 320
321 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos', join('playlists', 'hls') ]) 321 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ 'videos', join('playlists', 'hls') ])
322 }) 322 })
323 323
324 after(async function () { 324 after(async function () {
@@ -368,7 +368,7 @@ describe('Test videos redundancy', function () {
368 await check1WebSeed() 368 await check1WebSeed()
369 await check0PlaylistRedundancies() 369 await check0PlaylistRedundancies()
370 370
371 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ]) 371 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ 'videos' ])
372 }) 372 })
373 373
374 after(async function () { 374 after(async function () {
@@ -437,7 +437,7 @@ describe('Test videos redundancy', function () {
437 await waitJobs(servers) 437 await waitJobs(servers)
438 438
439 for (const server of servers) { 439 for (const server of servers) {
440 await checkVideoFilesWereRemoved(video1Server2UUID, server.serverNumber) 440 await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber)
441 } 441 }
442 }) 442 })
443 443
@@ -572,7 +572,7 @@ describe('Test videos redundancy', function () {
572 572
573 await waitJobs(servers) 573 await waitJobs(servers)
574 574
575 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ join('redundancy', 'hls') ]) 575 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ join('redundancy', 'hls') ])
576 }) 576 })
577 577
578 after(async function () { 578 after(async function () {
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index 22d87b88c..fa3e250ec 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -15,7 +15,6 @@ import {
15 createUser, 15 createUser,
16 dateIsValid, 16 dateIsValid,
17 doubleFollow, 17 doubleFollow,
18 flushAndRunServer,
19 flushAndRunMultipleServers, 18 flushAndRunMultipleServers,
20 getLocalVideos, 19 getLocalVideos,
21 getVideo, 20 getVideo,
@@ -697,8 +696,8 @@ describe('Test multiple servers', function () {
697 696
698 it('Should not have files of videos 3 and 3-2 on each server', async function () { 697 it('Should not have files of videos 3 and 3-2 on each server', async function () {
699 for (const server of servers) { 698 for (const server of servers) {
700 await checkVideoFilesWereRemoved(toRemove[0].uuid, server.serverNumber) 699 await checkVideoFilesWereRemoved(toRemove[0].uuid, server.internalServerNumber)
701 await checkVideoFilesWereRemoved(toRemove[1].uuid, server.serverNumber) 700 await checkVideoFilesWereRemoved(toRemove[1].uuid, server.internalServerNumber)
702 } 701 }
703 }) 702 })
704 703
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts
index d1ac48292..7a77a03ad 100644
--- a/shared/extra-utils/videos/videos.ts
+++ b/shared/extra-utils/videos/videos.ts
@@ -465,7 +465,7 @@ function rateVideo (url: string, accessToken: string, id: number, rating: string
465function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) { 465function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) {
466 return new Promise<any>((res, rej) => { 466 return new Promise<any>((res, rej) => {
467 const torrentName = videoUUID + '-' + resolution + '.torrent' 467 const torrentName = videoUUID + '-' + resolution + '.torrent'
468 const torrentPath = join(root(), 'test' + server.serverNumber, 'torrents', torrentName) 468 const torrentPath = join(root(), 'test' + server.internalServerNumber, 'torrents', torrentName)
469 readFile(torrentPath, (err, data) => { 469 readFile(torrentPath, (err, data) => {
470 if (err) return rej(err) 470 if (err) return rej(err)
471 471