]>
Commit | Line | Data |
---|---|---|
0c9668f7 C |
1 | import express from 'express' |
2 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | |
3 | import { proxifyHLS, proxifyWebTorrentFile } from '@server/lib/object-storage' | |
4 | import { VideoPathManager } from '@server/lib/video-path-manager' | |
5e47f6ab | 5 | import { getStudioTaskFilePath } from '@server/lib/video-studio' |
0c9668f7 C |
6 | import { asyncMiddleware } from '@server/middlewares' |
7 | import { jobOfRunnerGetValidator } from '@server/middlewares/validators/runners' | |
5e47f6ab C |
8 | import { |
9 | runnerJobGetVideoStudioTaskFileValidator, | |
10 | runnerJobGetVideoTranscodingFileValidator | |
11 | } from '@server/middlewares/validators/runners/job-files' | |
0c9668f7 C |
12 | import { VideoStorage } from '@shared/models' |
13 | ||
14 | const lTags = loggerTagsFactory('api', 'runner') | |
15 | ||
16 | const runnerJobFilesRouter = express.Router() | |
17 | ||
18 | runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/max-quality', | |
19 | asyncMiddleware(jobOfRunnerGetValidator), | |
20 | asyncMiddleware(runnerJobGetVideoTranscodingFileValidator), | |
21 | asyncMiddleware(getMaxQualityVideoFile) | |
22 | ) | |
23 | ||
24 | runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/previews/max-quality', | |
25 | asyncMiddleware(jobOfRunnerGetValidator), | |
26 | asyncMiddleware(runnerJobGetVideoTranscodingFileValidator), | |
27 | getMaxQualityVideoPreview | |
28 | ) | |
29 | ||
5e47f6ab C |
30 | runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/studio/task-files/:filename', |
31 | asyncMiddleware(jobOfRunnerGetValidator), | |
32 | asyncMiddleware(runnerJobGetVideoTranscodingFileValidator), | |
33 | runnerJobGetVideoStudioTaskFileValidator, | |
ab14f0e0 | 34 | getVideoStudioTaskFile |
5e47f6ab C |
35 | ) |
36 | ||
0c9668f7 C |
37 | // --------------------------------------------------------------------------- |
38 | ||
39 | export { | |
40 | runnerJobFilesRouter | |
41 | } | |
42 | ||
43 | // --------------------------------------------------------------------------- | |
44 | ||
45 | async function getMaxQualityVideoFile (req: express.Request, res: express.Response) { | |
46 | const runnerJob = res.locals.runnerJob | |
47 | const runner = runnerJob.Runner | |
48 | const video = res.locals.videoAll | |
49 | ||
50 | logger.info( | |
51 | 'Get max quality file of video %s of job %s for runner %s', video.uuid, runnerJob.uuid, runner.name, | |
52 | lTags(runner.name, runnerJob.id, runnerJob.type) | |
53 | ) | |
54 | ||
55 | const file = video.getMaxQualityFile() | |
56 | ||
57 | if (file.storage === VideoStorage.OBJECT_STORAGE) { | |
58 | if (file.isHLS()) { | |
59 | return proxifyHLS({ | |
60 | req, | |
61 | res, | |
62 | filename: file.filename, | |
63 | playlist: video.getHLSPlaylist(), | |
64 | reinjectVideoFileToken: false, | |
65 | video | |
66 | }) | |
67 | } | |
68 | ||
69 | // Web video | |
70 | return proxifyWebTorrentFile({ | |
71 | req, | |
72 | res, | |
73 | filename: file.filename | |
74 | }) | |
75 | } | |
76 | ||
77 | return VideoPathManager.Instance.makeAvailableVideoFile(file, videoPath => { | |
78 | return res.sendFile(videoPath) | |
79 | }) | |
80 | } | |
81 | ||
82 | function getMaxQualityVideoPreview (req: express.Request, res: express.Response) { | |
83 | const runnerJob = res.locals.runnerJob | |
84 | const runner = runnerJob.Runner | |
85 | const video = res.locals.videoAll | |
86 | ||
87 | logger.info( | |
88 | 'Get max quality preview file of video %s of job %s for runner %s', video.uuid, runnerJob.uuid, runner.name, | |
89 | lTags(runner.name, runnerJob.id, runnerJob.type) | |
90 | ) | |
91 | ||
92 | const file = video.getPreview() | |
93 | ||
94 | return res.sendFile(file.getPath()) | |
95 | } | |
5e47f6ab | 96 | |
ab14f0e0 | 97 | function getVideoStudioTaskFile (req: express.Request, res: express.Response) { |
5e47f6ab C |
98 | const runnerJob = res.locals.runnerJob |
99 | const runner = runnerJob.Runner | |
100 | const video = res.locals.videoAll | |
101 | const filename = req.params.filename | |
102 | ||
103 | logger.info( | |
ab14f0e0 | 104 | 'Get video studio task file %s of video %s of job %s for runner %s', filename, video.uuid, runnerJob.uuid, runner.name, |
5e47f6ab C |
105 | lTags(runner.name, runnerJob.id, runnerJob.type) |
106 | ) | |
107 | ||
108 | return res.sendFile(getStudioTaskFilePath(filename)) | |
109 | } |