]>
Commit | Line | Data |
---|---|---|
ad5db104 | 1 | import express from 'express' |
ad5db104 | 2 | import { logger, loggerTagsFactory } from '@server/helpers/logger' |
b42c2c7e | 3 | import { Hooks } from '@server/lib/plugins/hooks' |
0c9668f7 C |
4 | import { createTranscodingJobs } from '@server/lib/transcoding/create-transcoding-job' |
5 | import { computeResolutionsToTranscode } from '@server/lib/transcoding/transcoding-resolutions' | |
ad5db104 C |
6 | import { HttpStatusCode, UserRight, VideoState, VideoTranscodingCreate } from '@shared/models' |
7 | import { asyncMiddleware, authenticate, createTranscodingValidator, ensureUserHasRight } from '../../../middlewares' | |
8 | ||
9 | const lTags = loggerTagsFactory('api', 'video') | |
10 | const transcodingRouter = express.Router() | |
11 | ||
12 | transcodingRouter.post('/:videoId/transcoding', | |
13 | authenticate, | |
14 | ensureUserHasRight(UserRight.RUN_VIDEO_TRANSCODING), | |
15 | asyncMiddleware(createTranscodingValidator), | |
16 | asyncMiddleware(createTranscoding) | |
17 | ) | |
18 | ||
19 | // --------------------------------------------------------------------------- | |
20 | ||
21 | export { | |
22 | transcodingRouter | |
23 | } | |
24 | ||
25 | // --------------------------------------------------------------------------- | |
26 | ||
27 | async function createTranscoding (req: express.Request, res: express.Response) { | |
28 | const video = res.locals.videoAll | |
0f11ec8d | 29 | logger.info('Creating %s transcoding job for %s.', req.body.transcodingType, video.url, lTags()) |
ad5db104 C |
30 | |
31 | const body: VideoTranscodingCreate = req.body | |
32 | ||
a32bf8cd C |
33 | const { resolution: maxResolution, hasAudio } = await video.probeMaxQualityFile() |
34 | ||
ebb9e53a | 35 | const resolutions = await Hooks.wrapObject( |
a32bf8cd | 36 | computeResolutionsToTranscode({ input: maxResolution, type: 'vod', includeInput: true, strictLower: false, hasAudio }), |
64fd6158 | 37 | 'filter:transcoding.manual.resolutions-to-transcode.result', |
ebb9e53a C |
38 | body |
39 | ) | |
40 | ||
41 | if (resolutions.length === 0) { | |
42 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) | |
43 | } | |
ad5db104 C |
44 | |
45 | video.state = VideoState.TO_TRANSCODE | |
46 | await video.save() | |
47 | ||
0c9668f7 C |
48 | await createTranscodingJobs({ |
49 | video, | |
50 | resolutions, | |
51 | transcodingType: body.transcodingType, | |
b42c2c7e | 52 | isNewVideo: false, |
0c9668f7 | 53 | user: null // Don't specify priority since these transcoding jobs are fired by the admin |
b42c2c7e | 54 | }) |
b42c2c7e | 55 | |
0c9668f7 | 56 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) |
b42c2c7e | 57 | } |