diff options
author | Chocobozzz <me@florianbigard.com> | 2022-07-29 14:50:41 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-08-01 14:55:10 +0200 |
commit | 1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7 (patch) | |
tree | a6554ee0a3ccc2ae402665b2ecf57bb38fd0ed72 /server/lib/video-file.ts | |
parent | 12d84abeca4917d2f1e3f308010bfcd56d37cb7c (diff) | |
download | PeerTube-1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7.tar.gz PeerTube-1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7.tar.zst PeerTube-1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7.zip |
Add ability to delete a specific video file
Diffstat (limited to 'server/lib/video-file.ts')
-rw-r--r-- | server/lib/video-file.ts | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/server/lib/video-file.ts b/server/lib/video-file.ts new file mode 100644 index 000000000..2ab7190f1 --- /dev/null +++ b/server/lib/video-file.ts | |||
@@ -0,0 +1,69 @@ | |||
1 | import { logger } from '@server/helpers/logger' | ||
2 | import { MVideoWithAllFiles } from '@server/types/models' | ||
3 | import { lTags } from './object-storage/shared' | ||
4 | |||
5 | async function removeHLSPlaylist (video: MVideoWithAllFiles) { | ||
6 | const hls = video.getHLSPlaylist() | ||
7 | if (!hls) return | ||
8 | |||
9 | await video.removeStreamingPlaylistFiles(hls) | ||
10 | await hls.destroy() | ||
11 | |||
12 | video.VideoStreamingPlaylists = video.VideoStreamingPlaylists.filter(p => p.id !== hls.id) | ||
13 | } | ||
14 | |||
15 | async function removeHLSFile (video: MVideoWithAllFiles, fileToDeleteId: number) { | ||
16 | logger.info('Deleting HLS file %d of %s.', fileToDeleteId, video.url, lTags(video.uuid)) | ||
17 | |||
18 | const hls = video.getHLSPlaylist() | ||
19 | const files = hls.VideoFiles | ||
20 | |||
21 | if (files.length === 1) { | ||
22 | await removeHLSPlaylist(video) | ||
23 | return undefined | ||
24 | } | ||
25 | |||
26 | const toDelete = files.find(f => f.id === fileToDeleteId) | ||
27 | await video.removeStreamingPlaylistVideoFile(video.getHLSPlaylist(), toDelete) | ||
28 | await toDelete.destroy() | ||
29 | |||
30 | hls.VideoFiles = hls.VideoFiles.filter(f => f.id !== toDelete.id) | ||
31 | |||
32 | return hls | ||
33 | } | ||
34 | |||
35 | // --------------------------------------------------------------------------- | ||
36 | |||
37 | async function removeAllWebTorrentFiles (video: MVideoWithAllFiles) { | ||
38 | for (const file of video.VideoFiles) { | ||
39 | await video.removeWebTorrentFile(file) | ||
40 | await file.destroy() | ||
41 | } | ||
42 | |||
43 | video.VideoFiles = [] | ||
44 | |||
45 | return video | ||
46 | } | ||
47 | |||
48 | async function removeWebTorrentFile (video: MVideoWithAllFiles, fileToDeleteId: number) { | ||
49 | const files = video.VideoFiles | ||
50 | |||
51 | if (files.length === 1) { | ||
52 | return removeAllWebTorrentFiles(video) | ||
53 | } | ||
54 | |||
55 | const toDelete = files.find(f => f.id === fileToDeleteId) | ||
56 | await video.removeWebTorrentFile(toDelete) | ||
57 | await toDelete.destroy() | ||
58 | |||
59 | video.VideoFiles = files.filter(f => f.id !== toDelete.id) | ||
60 | |||
61 | return video | ||
62 | } | ||
63 | |||
64 | export { | ||
65 | removeHLSPlaylist, | ||
66 | removeHLSFile, | ||
67 | removeAllWebTorrentFiles, | ||
68 | removeWebTorrentFile | ||
69 | } | ||