aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/videos/files.ts79
-rw-r--r--server/controllers/api/videos/index.ts15
-rw-r--r--server/controllers/api/videos/update.ts2
3 files changed, 82 insertions, 14 deletions
diff --git a/server/controllers/api/videos/files.ts b/server/controllers/api/videos/files.ts
new file mode 100644
index 000000000..2fe4b5a3f
--- /dev/null
+++ b/server/controllers/api/videos/files.ts
@@ -0,0 +1,79 @@
1import express from 'express'
2import toInt from 'validator/lib/toInt'
3import { logger, loggerTagsFactory } from '@server/helpers/logger'
4import { federateVideoIfNeeded } from '@server/lib/activitypub/videos'
5import { VideoFileModel } from '@server/models/video/video-file'
6import { HttpStatusCode } from '@shared/models'
7import {
8 asyncMiddleware,
9 authenticate,
10 videoFileMetadataGetValidator,
11 videoFilesDeleteHLSValidator,
12 videoFilesDeleteWebTorrentValidator
13} from '../../../middlewares'
14
15const lTags = loggerTagsFactory('api', 'video')
16const filesRouter = express.Router()
17
18filesRouter.get('/:id/metadata/:videoFileId',
19 asyncMiddleware(videoFileMetadataGetValidator),
20 asyncMiddleware(getVideoFileMetadata)
21)
22
23filesRouter.delete('/:id/hls',
24 authenticate,
25 asyncMiddleware(videoFilesDeleteHLSValidator),
26 asyncMiddleware(removeHLSPlaylist)
27)
28
29filesRouter.delete('/:id/webtorrent',
30 authenticate,
31 asyncMiddleware(videoFilesDeleteWebTorrentValidator),
32 asyncMiddleware(removeWebTorrentFiles)
33)
34
35// ---------------------------------------------------------------------------
36
37export {
38 filesRouter
39}
40
41// ---------------------------------------------------------------------------
42
43async function getVideoFileMetadata (req: express.Request, res: express.Response) {
44 const videoFile = await VideoFileModel.loadWithMetadata(toInt(req.params.videoFileId))
45
46 return res.json(videoFile.metadata)
47}
48
49async function removeHLSPlaylist (req: express.Request, res: express.Response) {
50 const video = res.locals.videoAll
51
52 logger.info('Deleting HLS playlist of %s.', video.url, lTags(video.uuid))
53
54 const hls = video.getHLSPlaylist()
55 await video.removeStreamingPlaylistFiles(hls)
56 await hls.destroy()
57
58 video.VideoStreamingPlaylists = video.VideoStreamingPlaylists.filter(p => p.id !== hls.id)
59
60 await federateVideoIfNeeded(video, false, undefined)
61
62 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
63}
64
65async function removeWebTorrentFiles (req: express.Request, res: express.Response) {
66 const video = res.locals.videoAll
67
68 logger.info('Deleting WebTorrent files of %s.', video.url, lTags(video.uuid))
69
70 for (const file of video.VideoFiles) {
71 await video.removeWebTorrentFileAndTorrent(file)
72 await file.destroy()
73 }
74
75 video.VideoFiles = []
76 await federateVideoIfNeeded(video, false, undefined)
77
78 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
79}
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 72b382595..2d088a73e 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -1,5 +1,4 @@
1import express from 'express' 1import express from 'express'
2import toInt from 'validator/lib/toInt'
3import { pickCommonVideoQuery } from '@server/helpers/query' 2import { pickCommonVideoQuery } from '@server/helpers/query'
4import { doJSONRequest } from '@server/helpers/requests' 3import { doJSONRequest } from '@server/helpers/requests'
5import { VideoViews } from '@server/lib/video-views' 4import { VideoViews } from '@server/lib/video-views'
@@ -27,17 +26,16 @@ import {
27 paginationValidator, 26 paginationValidator,
28 setDefaultPagination, 27 setDefaultPagination,
29 setDefaultVideosSort, 28 setDefaultVideosSort,
30 videoFileMetadataGetValidator,
31 videosCustomGetValidator, 29 videosCustomGetValidator,
32 videosGetValidator, 30 videosGetValidator,
33 videosRemoveValidator, 31 videosRemoveValidator,
34 videosSortValidator 32 videosSortValidator
35} from '../../../middlewares' 33} from '../../../middlewares'
36import { VideoModel } from '../../../models/video/video' 34import { VideoModel } from '../../../models/video/video'
37import { VideoFileModel } from '../../../models/video/video-file'
38import { blacklistRouter } from './blacklist' 35import { blacklistRouter } from './blacklist'
39import { videoCaptionsRouter } from './captions' 36import { videoCaptionsRouter } from './captions'
40import { videoCommentRouter } from './comment' 37import { videoCommentRouter } from './comment'
38import { filesRouter } from './files'
41import { videoImportsRouter } from './import' 39import { videoImportsRouter } from './import'
42import { liveRouter } from './live' 40import { liveRouter } from './live'
43import { ownershipVideoRouter } from './ownership' 41import { ownershipVideoRouter } from './ownership'
@@ -59,6 +57,7 @@ videosRouter.use('/', watchingRouter)
59videosRouter.use('/', liveRouter) 57videosRouter.use('/', liveRouter)
60videosRouter.use('/', uploadRouter) 58videosRouter.use('/', uploadRouter)
61videosRouter.use('/', updateRouter) 59videosRouter.use('/', updateRouter)
60videosRouter.use('/', filesRouter)
62 61
63videosRouter.get('/categories', 62videosRouter.get('/categories',
64 openapiOperationDoc({ operationId: 'getCategories' }), 63 openapiOperationDoc({ operationId: 'getCategories' }),
@@ -93,10 +92,6 @@ videosRouter.get('/:id/description',
93 asyncMiddleware(videosGetValidator), 92 asyncMiddleware(videosGetValidator),
94 asyncMiddleware(getVideoDescription) 93 asyncMiddleware(getVideoDescription)
95) 94)
96videosRouter.get('/:id/metadata/:videoFileId',
97 asyncMiddleware(videoFileMetadataGetValidator),
98 asyncMiddleware(getVideoFileMetadata)
99)
100videosRouter.get('/:id', 95videosRouter.get('/:id',
101 openapiOperationDoc({ operationId: 'getVideo' }), 96 openapiOperationDoc({ operationId: 'getVideo' }),
102 optionalAuthenticate, 97 optionalAuthenticate,
@@ -177,12 +172,6 @@ async function getVideoDescription (req: express.Request, res: express.Response)
177 return res.json({ description }) 172 return res.json({ description })
178} 173}
179 174
180async function getVideoFileMetadata (req: express.Request, res: express.Response) {
181 const videoFile = await VideoFileModel.loadWithMetadata(toInt(req.params.videoFileId))
182
183 return res.json(videoFile.metadata)
184}
185
186async function listVideos (req: express.Request, res: express.Response) { 175async function listVideos (req: express.Request, res: express.Response) {
187 const serverActor = await getServerActor() 176 const serverActor = await getServerActor()
188 177
diff --git a/server/controllers/api/videos/update.ts b/server/controllers/api/videos/update.ts
index a0aa13d71..de5d94d55 100644
--- a/server/controllers/api/videos/update.ts
+++ b/server/controllers/api/videos/update.ts
@@ -51,7 +51,7 @@ export {
51 51
52// --------------------------------------------------------------------------- 52// ---------------------------------------------------------------------------
53 53
54export async function updateVideo (req: express.Request, res: express.Response) { 54async function updateVideo (req: express.Request, res: express.Response) {
55 const videoFromReq = res.locals.videoAll 55 const videoFromReq = res.locals.videoAll
56 const videoFieldsSave = videoFromReq.toJSON() 56 const videoFieldsSave = videoFromReq.toJSON()
57 const oldVideoAuditView = new VideoAuditView(videoFromReq.toFormattedDetailsJSON()) 57 const oldVideoAuditView = new VideoAuditView(videoFromReq.toFormattedDetailsJSON())