aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/files.ts62
1 files changed, 49 insertions, 13 deletions
diff --git a/server/controllers/api/videos/files.ts b/server/controllers/api/videos/files.ts
index 0fbda280e..6d9c0b843 100644
--- a/server/controllers/api/videos/files.ts
+++ b/server/controllers/api/videos/files.ts
@@ -2,6 +2,7 @@ import express from 'express'
2import toInt from 'validator/lib/toInt' 2import toInt from 'validator/lib/toInt'
3import { logger, loggerTagsFactory } from '@server/helpers/logger' 3import { logger, loggerTagsFactory } from '@server/helpers/logger'
4import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' 4import { federateVideoIfNeeded } from '@server/lib/activitypub/videos'
5import { removeAllWebTorrentFiles, removeHLSFile, removeHLSPlaylist, removeWebTorrentFile } from '@server/lib/video-file'
5import { VideoFileModel } from '@server/models/video/video-file' 6import { VideoFileModel } from '@server/models/video/video-file'
6import { HttpStatusCode, UserRight } from '@shared/models' 7import { HttpStatusCode, UserRight } from '@shared/models'
7import { 8import {
@@ -9,10 +10,13 @@ import {
9 authenticate, 10 authenticate,
10 ensureUserHasRight, 11 ensureUserHasRight,
11 videoFileMetadataGetValidator, 12 videoFileMetadataGetValidator,
13 videoFilesDeleteHLSFileValidator,
12 videoFilesDeleteHLSValidator, 14 videoFilesDeleteHLSValidator,
15 videoFilesDeleteWebTorrentFileValidator,
13 videoFilesDeleteWebTorrentValidator, 16 videoFilesDeleteWebTorrentValidator,
14 videosGetValidator 17 videosGetValidator
15} from '../../../middlewares' 18} from '../../../middlewares'
19import { updatePlaylistAfterFileChange } from '@server/lib/hls'
16 20
17const lTags = loggerTagsFactory('api', 'video') 21const lTags = loggerTagsFactory('api', 'video')
18const filesRouter = express.Router() 22const filesRouter = express.Router()
@@ -27,14 +31,26 @@ filesRouter.delete('/:id/hls',
27 authenticate, 31 authenticate,
28 ensureUserHasRight(UserRight.MANAGE_VIDEO_FILES), 32 ensureUserHasRight(UserRight.MANAGE_VIDEO_FILES),
29 asyncMiddleware(videoFilesDeleteHLSValidator), 33 asyncMiddleware(videoFilesDeleteHLSValidator),
30 asyncMiddleware(removeHLSPlaylist) 34 asyncMiddleware(removeHLSPlaylistController)
35)
36filesRouter.delete('/:id/hls/:videoFileId',
37 authenticate,
38 ensureUserHasRight(UserRight.MANAGE_VIDEO_FILES),
39 asyncMiddleware(videoFilesDeleteHLSFileValidator),
40 asyncMiddleware(removeHLSFileController)
31) 41)
32 42
33filesRouter.delete('/:id/webtorrent', 43filesRouter.delete('/:id/webtorrent',
34 authenticate, 44 authenticate,
35 ensureUserHasRight(UserRight.MANAGE_VIDEO_FILES), 45 ensureUserHasRight(UserRight.MANAGE_VIDEO_FILES),
36 asyncMiddleware(videoFilesDeleteWebTorrentValidator), 46 asyncMiddleware(videoFilesDeleteWebTorrentValidator),
37 asyncMiddleware(removeWebTorrentFiles) 47 asyncMiddleware(removeAllWebTorrentFilesController)
48)
49filesRouter.delete('/:id/webtorrent/:videoFileId',
50 authenticate,
51 ensureUserHasRight(UserRight.MANAGE_VIDEO_FILES),
52 asyncMiddleware(videoFilesDeleteWebTorrentFileValidator),
53 asyncMiddleware(removeWebTorrentFileController)
38) 54)
39 55
40// --------------------------------------------------------------------------- 56// ---------------------------------------------------------------------------
@@ -51,33 +67,53 @@ async function getVideoFileMetadata (req: express.Request, res: express.Response
51 return res.json(videoFile.metadata) 67 return res.json(videoFile.metadata)
52} 68}
53 69
54async function removeHLSPlaylist (req: express.Request, res: express.Response) { 70// ---------------------------------------------------------------------------
71
72async function removeHLSPlaylistController (req: express.Request, res: express.Response) {
55 const video = res.locals.videoAll 73 const video = res.locals.videoAll
56 74
57 logger.info('Deleting HLS playlist of %s.', video.url, lTags(video.uuid)) 75 logger.info('Deleting HLS playlist of %s.', video.url, lTags(video.uuid))
76 await removeHLSPlaylist(video)
77
78 await federateVideoIfNeeded(video, false, undefined)
79
80 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
81}
82
83async function removeHLSFileController (req: express.Request, res: express.Response) {
84 const video = res.locals.videoAll
85 const videoFileId = +req.params.videoFileId
58 86
59 const hls = video.getHLSPlaylist() 87 logger.info('Deleting HLS file %d of %s.', videoFileId, video.url, lTags(video.uuid))
60 await video.removeStreamingPlaylistFiles(hls)
61 await hls.destroy()
62 88
63 video.VideoStreamingPlaylists = video.VideoStreamingPlaylists.filter(p => p.id !== hls.id) 89 const playlist = await removeHLSFile(video, videoFileId)
90 if (playlist) await updatePlaylistAfterFileChange(video, playlist)
64 91
65 await federateVideoIfNeeded(video, false, undefined) 92 await federateVideoIfNeeded(video, false, undefined)
66 93
67 return res.sendStatus(HttpStatusCode.NO_CONTENT_204) 94 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
68} 95}
69 96
70async function removeWebTorrentFiles (req: express.Request, res: express.Response) { 97// ---------------------------------------------------------------------------
98
99async function removeAllWebTorrentFilesController (req: express.Request, res: express.Response) {
71 const video = res.locals.videoAll 100 const video = res.locals.videoAll
72 101
73 logger.info('Deleting WebTorrent files of %s.', video.url, lTags(video.uuid)) 102 logger.info('Deleting WebTorrent files of %s.', video.url, lTags(video.uuid))
74 103
75 for (const file of video.VideoFiles) { 104 await removeAllWebTorrentFiles(video)
76 await video.removeWebTorrentFileAndTorrent(file) 105 await federateVideoIfNeeded(video, false, undefined)
77 await file.destroy() 106
78 } 107 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
108}
109
110async function removeWebTorrentFileController (req: express.Request, res: express.Response) {
111 const video = res.locals.videoAll
112
113 const videoFileId = +req.params.videoFileId
114 logger.info('Deleting WebTorrent file %d of %s.', videoFileId, video.url, lTags(video.uuid))
79 115
80 video.VideoFiles = [] 116 await removeWebTorrentFile(video, videoFileId)
81 await federateVideoIfNeeded(video, false, undefined) 117 await federateVideoIfNeeded(video, false, undefined)
82 118
83 return res.sendStatus(HttpStatusCode.NO_CONTENT_204) 119 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)