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.ts5
-rw-r--r--server/controllers/api/videos/index.ts2
-rw-r--r--server/controllers/api/videos/transcoding.ts62
3 files changed, 68 insertions, 1 deletions
diff --git a/server/controllers/api/videos/files.ts b/server/controllers/api/videos/files.ts
index 2fe4b5a3f..a8b32411d 100644
--- a/server/controllers/api/videos/files.ts
+++ b/server/controllers/api/videos/files.ts
@@ -3,10 +3,11 @@ import 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 { VideoFileModel } from '@server/models/video/video-file' 5import { VideoFileModel } from '@server/models/video/video-file'
6import { HttpStatusCode } from '@shared/models' 6import { HttpStatusCode, UserRight } from '@shared/models'
7import { 7import {
8 asyncMiddleware, 8 asyncMiddleware,
9 authenticate, 9 authenticate,
10 ensureUserHasRight,
10 videoFileMetadataGetValidator, 11 videoFileMetadataGetValidator,
11 videoFilesDeleteHLSValidator, 12 videoFilesDeleteHLSValidator,
12 videoFilesDeleteWebTorrentValidator 13 videoFilesDeleteWebTorrentValidator
@@ -22,12 +23,14 @@ filesRouter.get('/:id/metadata/:videoFileId',
22 23
23filesRouter.delete('/:id/hls', 24filesRouter.delete('/:id/hls',
24 authenticate, 25 authenticate,
26 ensureUserHasRight(UserRight.MANAGE_VIDEO_FILES),
25 asyncMiddleware(videoFilesDeleteHLSValidator), 27 asyncMiddleware(videoFilesDeleteHLSValidator),
26 asyncMiddleware(removeHLSPlaylist) 28 asyncMiddleware(removeHLSPlaylist)
27) 29)
28 30
29filesRouter.delete('/:id/webtorrent', 31filesRouter.delete('/:id/webtorrent',
30 authenticate, 32 authenticate,
33 ensureUserHasRight(UserRight.MANAGE_VIDEO_FILES),
31 asyncMiddleware(videoFilesDeleteWebTorrentValidator), 34 asyncMiddleware(videoFilesDeleteWebTorrentValidator),
32 asyncMiddleware(removeWebTorrentFiles) 35 asyncMiddleware(removeWebTorrentFiles)
33) 36)
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 2d088a73e..fc1bcc73d 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -40,6 +40,7 @@ import { videoImportsRouter } from './import'
40import { liveRouter } from './live' 40import { liveRouter } from './live'
41import { ownershipVideoRouter } from './ownership' 41import { ownershipVideoRouter } from './ownership'
42import { rateVideoRouter } from './rate' 42import { rateVideoRouter } from './rate'
43import { transcodingRouter } from './transcoding'
43import { updateRouter } from './update' 44import { updateRouter } from './update'
44import { uploadRouter } from './upload' 45import { uploadRouter } from './upload'
45import { watchingRouter } from './watching' 46import { watchingRouter } from './watching'
@@ -58,6 +59,7 @@ videosRouter.use('/', liveRouter)
58videosRouter.use('/', uploadRouter) 59videosRouter.use('/', uploadRouter)
59videosRouter.use('/', updateRouter) 60videosRouter.use('/', updateRouter)
60videosRouter.use('/', filesRouter) 61videosRouter.use('/', filesRouter)
62videosRouter.use('/', transcodingRouter)
61 63
62videosRouter.get('/categories', 64videosRouter.get('/categories',
63 openapiOperationDoc({ operationId: 'getCategories' }), 65 openapiOperationDoc({ operationId: 'getCategories' }),
diff --git a/server/controllers/api/videos/transcoding.ts b/server/controllers/api/videos/transcoding.ts
new file mode 100644
index 000000000..dd6fbd3de
--- /dev/null
+++ b/server/controllers/api/videos/transcoding.ts
@@ -0,0 +1,62 @@
1import express from 'express'
2import { computeLowerResolutionsToTranscode } from '@server/helpers/ffprobe-utils'
3import { logger, loggerTagsFactory } from '@server/helpers/logger'
4import { addTranscodingJob } from '@server/lib/video'
5import { HttpStatusCode, UserRight, VideoState, VideoTranscodingCreate } from '@shared/models'
6import { asyncMiddleware, authenticate, createTranscodingValidator, ensureUserHasRight } from '../../../middlewares'
7
8const lTags = loggerTagsFactory('api', 'video')
9const transcodingRouter = express.Router()
10
11transcodingRouter.post('/:videoId/transcoding',
12 authenticate,
13 ensureUserHasRight(UserRight.RUN_VIDEO_TRANSCODING),
14 asyncMiddleware(createTranscodingValidator),
15 asyncMiddleware(createTranscoding)
16)
17
18// ---------------------------------------------------------------------------
19
20export {
21 transcodingRouter
22}
23
24// ---------------------------------------------------------------------------
25
26async function createTranscoding (req: express.Request, res: express.Response) {
27 const video = res.locals.videoAll
28 logger.info('Creating %s transcoding job for %s.', req.body.type, video.url, lTags())
29
30 const body: VideoTranscodingCreate = req.body
31
32 const { resolution: maxResolution, isPortraitMode } = await video.getMaxQualityResolution()
33 const resolutions = computeLowerResolutionsToTranscode(maxResolution, 'vod').concat([ maxResolution ])
34
35 video.state = VideoState.TO_TRANSCODE
36 await video.save()
37
38 for (const resolution of resolutions) {
39 if (body.transcodingType === 'hls') {
40 await addTranscodingJob({
41 type: 'new-resolution-to-hls',
42 videoUUID: video.uuid,
43 resolution,
44 isPortraitMode,
45 copyCodecs: false,
46 isNewVideo: false,
47 autoDeleteWebTorrentIfNeeded: false,
48 isMaxQuality: maxResolution === resolution
49 })
50 } else if (body.transcodingType === 'webtorrent') {
51 await addTranscodingJob({
52 type: 'new-resolution-to-webtorrent',
53 videoUUID: video.uuid,
54 isNewVideo: false,
55 resolution: resolution,
56 isPortraitMode
57 })
58 }
59 }
60
61 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
62}