diff options
author | Chocobozzz <me@florianbigard.com> | 2023-04-21 14:55:10 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-05-09 08:57:34 +0200 |
commit | 0c9668f77901e7540e2c7045eb0f2974a4842a69 (patch) | |
tree | 226d3dd1565b0bb56588897af3b8530e6216e96b /server/controllers/api/runners/jobs-files.ts | |
parent | 6bcb854cdea8688a32240bc5719c7d139806e00b (diff) | |
download | PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.tar.gz PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.tar.zst PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.zip |
Implement remote runner jobs in server
Move ffmpeg functions to @shared
Diffstat (limited to 'server/controllers/api/runners/jobs-files.ts')
-rw-r--r-- | server/controllers/api/runners/jobs-files.ts | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/server/controllers/api/runners/jobs-files.ts b/server/controllers/api/runners/jobs-files.ts new file mode 100644 index 000000000..e43ce35f5 --- /dev/null +++ b/server/controllers/api/runners/jobs-files.ts | |||
@@ -0,0 +1,84 @@ | |||
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' | ||
5 | import { asyncMiddleware } from '@server/middlewares' | ||
6 | import { jobOfRunnerGetValidator } from '@server/middlewares/validators/runners' | ||
7 | import { runnerJobGetVideoTranscodingFileValidator } from '@server/middlewares/validators/runners/job-files' | ||
8 | import { VideoStorage } from '@shared/models' | ||
9 | |||
10 | const lTags = loggerTagsFactory('api', 'runner') | ||
11 | |||
12 | const runnerJobFilesRouter = express.Router() | ||
13 | |||
14 | runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/max-quality', | ||
15 | asyncMiddleware(jobOfRunnerGetValidator), | ||
16 | asyncMiddleware(runnerJobGetVideoTranscodingFileValidator), | ||
17 | asyncMiddleware(getMaxQualityVideoFile) | ||
18 | ) | ||
19 | |||
20 | runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/previews/max-quality', | ||
21 | asyncMiddleware(jobOfRunnerGetValidator), | ||
22 | asyncMiddleware(runnerJobGetVideoTranscodingFileValidator), | ||
23 | getMaxQualityVideoPreview | ||
24 | ) | ||
25 | |||
26 | // --------------------------------------------------------------------------- | ||
27 | |||
28 | export { | ||
29 | runnerJobFilesRouter | ||
30 | } | ||
31 | |||
32 | // --------------------------------------------------------------------------- | ||
33 | |||
34 | async function getMaxQualityVideoFile (req: express.Request, res: express.Response) { | ||
35 | const runnerJob = res.locals.runnerJob | ||
36 | const runner = runnerJob.Runner | ||
37 | const video = res.locals.videoAll | ||
38 | |||
39 | logger.info( | ||
40 | 'Get max quality file of video %s of job %s for runner %s', video.uuid, runnerJob.uuid, runner.name, | ||
41 | lTags(runner.name, runnerJob.id, runnerJob.type) | ||
42 | ) | ||
43 | |||
44 | const file = video.getMaxQualityFile() | ||
45 | |||
46 | if (file.storage === VideoStorage.OBJECT_STORAGE) { | ||
47 | if (file.isHLS()) { | ||
48 | return proxifyHLS({ | ||
49 | req, | ||
50 | res, | ||
51 | filename: file.filename, | ||
52 | playlist: video.getHLSPlaylist(), | ||
53 | reinjectVideoFileToken: false, | ||
54 | video | ||
55 | }) | ||
56 | } | ||
57 | |||
58 | // Web video | ||
59 | return proxifyWebTorrentFile({ | ||
60 | req, | ||
61 | res, | ||
62 | filename: file.filename | ||
63 | }) | ||
64 | } | ||
65 | |||
66 | return VideoPathManager.Instance.makeAvailableVideoFile(file, videoPath => { | ||
67 | return res.sendFile(videoPath) | ||
68 | }) | ||
69 | } | ||
70 | |||
71 | function getMaxQualityVideoPreview (req: express.Request, res: express.Response) { | ||
72 | const runnerJob = res.locals.runnerJob | ||
73 | const runner = runnerJob.Runner | ||
74 | const video = res.locals.videoAll | ||
75 | |||
76 | logger.info( | ||
77 | 'Get max quality preview file of video %s of job %s for runner %s', video.uuid, runnerJob.uuid, runner.name, | ||
78 | lTags(runner.name, runnerJob.id, runnerJob.type) | ||
79 | ) | ||
80 | |||
81 | const file = video.getPreview() | ||
82 | |||
83 | return res.sendFile(file.getPath()) | ||
84 | } | ||