diff options
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r-- | server/controllers/api/videos/files.ts | 5 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/videos/transcoding.ts | 62 |
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' | |||
3 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | 3 | import { logger, loggerTagsFactory } from '@server/helpers/logger' |
4 | import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' | 4 | import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' |
5 | import { VideoFileModel } from '@server/models/video/video-file' | 5 | import { VideoFileModel } from '@server/models/video/video-file' |
6 | import { HttpStatusCode } from '@shared/models' | 6 | import { HttpStatusCode, UserRight } from '@shared/models' |
7 | import { | 7 | import { |
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 | ||
23 | filesRouter.delete('/:id/hls', | 24 | filesRouter.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 | ||
29 | filesRouter.delete('/:id/webtorrent', | 31 | filesRouter.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' | |||
40 | import { liveRouter } from './live' | 40 | import { liveRouter } from './live' |
41 | import { ownershipVideoRouter } from './ownership' | 41 | import { ownershipVideoRouter } from './ownership' |
42 | import { rateVideoRouter } from './rate' | 42 | import { rateVideoRouter } from './rate' |
43 | import { transcodingRouter } from './transcoding' | ||
43 | import { updateRouter } from './update' | 44 | import { updateRouter } from './update' |
44 | import { uploadRouter } from './upload' | 45 | import { uploadRouter } from './upload' |
45 | import { watchingRouter } from './watching' | 46 | import { watchingRouter } from './watching' |
@@ -58,6 +59,7 @@ videosRouter.use('/', liveRouter) | |||
58 | videosRouter.use('/', uploadRouter) | 59 | videosRouter.use('/', uploadRouter) |
59 | videosRouter.use('/', updateRouter) | 60 | videosRouter.use('/', updateRouter) |
60 | videosRouter.use('/', filesRouter) | 61 | videosRouter.use('/', filesRouter) |
62 | videosRouter.use('/', transcodingRouter) | ||
61 | 63 | ||
62 | videosRouter.get('/categories', | 64 | videosRouter.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 @@ | |||
1 | import express from 'express' | ||
2 | import { computeLowerResolutionsToTranscode } from '@server/helpers/ffprobe-utils' | ||
3 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | ||
4 | import { addTranscodingJob } from '@server/lib/video' | ||
5 | import { HttpStatusCode, UserRight, VideoState, VideoTranscodingCreate } from '@shared/models' | ||
6 | import { asyncMiddleware, authenticate, createTranscodingValidator, ensureUserHasRight } from '../../../middlewares' | ||
7 | |||
8 | const lTags = loggerTagsFactory('api', 'video') | ||
9 | const transcodingRouter = express.Router() | ||
10 | |||
11 | transcodingRouter.post('/:videoId/transcoding', | ||
12 | authenticate, | ||
13 | ensureUserHasRight(UserRight.RUN_VIDEO_TRANSCODING), | ||
14 | asyncMiddleware(createTranscodingValidator), | ||
15 | asyncMiddleware(createTranscoding) | ||
16 | ) | ||
17 | |||
18 | // --------------------------------------------------------------------------- | ||
19 | |||
20 | export { | ||
21 | transcodingRouter | ||
22 | } | ||
23 | |||
24 | // --------------------------------------------------------------------------- | ||
25 | |||
26 | async 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 | } | ||