aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/runners/jobs-files.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-04-21 14:55:10 +0200
committerChocobozzz <chocobozzz@cpy.re>2023-05-09 08:57:34 +0200
commit0c9668f77901e7540e2c7045eb0f2974a4842a69 (patch)
tree226d3dd1565b0bb56588897af3b8530e6216e96b /server/controllers/api/runners/jobs-files.ts
parent6bcb854cdea8688a32240bc5719c7d139806e00b (diff)
downloadPeerTube-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.ts84
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 @@
1import express from 'express'
2import { logger, loggerTagsFactory } from '@server/helpers/logger'
3import { proxifyHLS, proxifyWebTorrentFile } from '@server/lib/object-storage'
4import { VideoPathManager } from '@server/lib/video-path-manager'
5import { asyncMiddleware } from '@server/middlewares'
6import { jobOfRunnerGetValidator } from '@server/middlewares/validators/runners'
7import { runnerJobGetVideoTranscodingFileValidator } from '@server/middlewares/validators/runners/job-files'
8import { VideoStorage } from '@shared/models'
9
10const lTags = loggerTagsFactory('api', 'runner')
11
12const runnerJobFilesRouter = express.Router()
13
14runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/max-quality',
15 asyncMiddleware(jobOfRunnerGetValidator),
16 asyncMiddleware(runnerJobGetVideoTranscodingFileValidator),
17 asyncMiddleware(getMaxQualityVideoFile)
18)
19
20runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/previews/max-quality',
21 asyncMiddleware(jobOfRunnerGetValidator),
22 asyncMiddleware(runnerJobGetVideoTranscodingFileValidator),
23 getMaxQualityVideoPreview
24)
25
26// ---------------------------------------------------------------------------
27
28export {
29 runnerJobFilesRouter
30}
31
32// ---------------------------------------------------------------------------
33
34async 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
71function 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}