aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video-file.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/video-file.ts')
-rw-r--r--server/lib/video-file.ts69
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 @@
1import { logger } from '@server/helpers/logger'
2import { MVideoWithAllFiles } from '@server/types/models'
3import { lTags } from './object-storage/shared'
4
5async 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
15async 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
37async 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
48async 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
64export {
65 removeHLSPlaylist,
66 removeHLSFile,
67 removeAllWebTorrentFiles,
68 removeWebTorrentFile
69}