diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-31 14:34:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-08-11 15:02:33 +0200 |
commit | 3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch) | |
tree | e4510b39bdac9c318fdb4b47018d08f15368b8f0 /server/controllers/api/runners/jobs-files.ts | |
parent | 04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff) | |
download | PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip |
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge
conflicts, but it's a major step forward:
* Server can be faster at startup because imports() are async and we can
easily lazy import big modules
* Angular doesn't seem to support ES import (with .js extension), so we
had to correctly organize peertube into a monorepo:
* Use yarn workspace feature
* Use typescript reference projects for dependencies
* Shared projects have been moved into "packages", each one is now a
node module (with a dedicated package.json/tsconfig.json)
* server/tools have been moved into apps/ and is now a dedicated app
bundled and published on NPM so users don't have to build peertube
cli tools manually
* server/tests have been moved into packages/ so we don't compile
them every time we want to run the server
* Use isolatedModule option:
* Had to move from const enum to const
(https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums)
* Had to explictely specify "type" imports when used in decorators
* Prefer tsx (that uses esbuild under the hood) instead of ts-node to
load typescript files (tests with mocha or scripts):
* To reduce test complexity as esbuild doesn't support decorator
metadata, we only test server files that do not import server
models
* We still build tests files into js files for a faster CI
* Remove unmaintained peertube CLI import script
* Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'server/controllers/api/runners/jobs-files.ts')
-rw-r--r-- | server/controllers/api/runners/jobs-files.ts | 112 |
1 files changed, 0 insertions, 112 deletions
diff --git a/server/controllers/api/runners/jobs-files.ts b/server/controllers/api/runners/jobs-files.ts deleted file mode 100644 index d28f43701..000000000 --- a/server/controllers/api/runners/jobs-files.ts +++ /dev/null | |||
@@ -1,112 +0,0 @@ | |||
1 | import express from 'express' | ||
2 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | ||
3 | import { proxifyHLS, proxifyWebVideoFile } from '@server/lib/object-storage' | ||
4 | import { VideoPathManager } from '@server/lib/video-path-manager' | ||
5 | import { getStudioTaskFilePath } from '@server/lib/video-studio' | ||
6 | import { apiRateLimiter, asyncMiddleware } from '@server/middlewares' | ||
7 | import { jobOfRunnerGetValidatorFactory } from '@server/middlewares/validators/runners' | ||
8 | import { | ||
9 | runnerJobGetVideoStudioTaskFileValidator, | ||
10 | runnerJobGetVideoTranscodingFileValidator | ||
11 | } from '@server/middlewares/validators/runners/job-files' | ||
12 | import { RunnerJobState, 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 | apiRateLimiter, | ||
20 | asyncMiddleware(jobOfRunnerGetValidatorFactory([ RunnerJobState.PROCESSING ])), | ||
21 | asyncMiddleware(runnerJobGetVideoTranscodingFileValidator), | ||
22 | asyncMiddleware(getMaxQualityVideoFile) | ||
23 | ) | ||
24 | |||
25 | runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/previews/max-quality', | ||
26 | apiRateLimiter, | ||
27 | asyncMiddleware(jobOfRunnerGetValidatorFactory([ RunnerJobState.PROCESSING ])), | ||
28 | asyncMiddleware(runnerJobGetVideoTranscodingFileValidator), | ||
29 | getMaxQualityVideoPreview | ||
30 | ) | ||
31 | |||
32 | runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/studio/task-files/:filename', | ||
33 | apiRateLimiter, | ||
34 | asyncMiddleware(jobOfRunnerGetValidatorFactory([ RunnerJobState.PROCESSING ])), | ||
35 | asyncMiddleware(runnerJobGetVideoTranscodingFileValidator), | ||
36 | runnerJobGetVideoStudioTaskFileValidator, | ||
37 | getVideoStudioTaskFile | ||
38 | ) | ||
39 | |||
40 | // --------------------------------------------------------------------------- | ||
41 | |||
42 | export { | ||
43 | runnerJobFilesRouter | ||
44 | } | ||
45 | |||
46 | // --------------------------------------------------------------------------- | ||
47 | |||
48 | async function getMaxQualityVideoFile (req: express.Request, res: express.Response) { | ||
49 | const runnerJob = res.locals.runnerJob | ||
50 | const runner = runnerJob.Runner | ||
51 | const video = res.locals.videoAll | ||
52 | |||
53 | logger.info( | ||
54 | 'Get max quality file of video %s of job %s for runner %s', video.uuid, runnerJob.uuid, runner.name, | ||
55 | lTags(runner.name, runnerJob.id, runnerJob.type) | ||
56 | ) | ||
57 | |||
58 | const file = video.getMaxQualityFile() | ||
59 | |||
60 | if (file.storage === VideoStorage.OBJECT_STORAGE) { | ||
61 | if (file.isHLS()) { | ||
62 | return proxifyHLS({ | ||
63 | req, | ||
64 | res, | ||
65 | filename: file.filename, | ||
66 | playlist: video.getHLSPlaylist(), | ||
67 | reinjectVideoFileToken: false, | ||
68 | video | ||
69 | }) | ||
70 | } | ||
71 | |||
72 | // Web video | ||
73 | return proxifyWebVideoFile({ | ||
74 | req, | ||
75 | res, | ||
76 | filename: file.filename | ||
77 | }) | ||
78 | } | ||
79 | |||
80 | return VideoPathManager.Instance.makeAvailableVideoFile(file, videoPath => { | ||
81 | return res.sendFile(videoPath) | ||
82 | }) | ||
83 | } | ||
84 | |||
85 | function getMaxQualityVideoPreview (req: express.Request, res: express.Response) { | ||
86 | const runnerJob = res.locals.runnerJob | ||
87 | const runner = runnerJob.Runner | ||
88 | const video = res.locals.videoAll | ||
89 | |||
90 | logger.info( | ||
91 | 'Get max quality preview file of video %s of job %s for runner %s', video.uuid, runnerJob.uuid, runner.name, | ||
92 | lTags(runner.name, runnerJob.id, runnerJob.type) | ||
93 | ) | ||
94 | |||
95 | const file = video.getPreview() | ||
96 | |||
97 | return res.sendFile(file.getPath()) | ||
98 | } | ||
99 | |||
100 | function getVideoStudioTaskFile (req: express.Request, res: express.Response) { | ||
101 | const runnerJob = res.locals.runnerJob | ||
102 | const runner = runnerJob.Runner | ||
103 | const video = res.locals.videoAll | ||
104 | const filename = req.params.filename | ||
105 | |||
106 | logger.info( | ||
107 | 'Get video studio task file %s of video %s of job %s for runner %s', filename, video.uuid, runnerJob.uuid, runner.name, | ||
108 | lTags(runner.name, runnerJob.id, runnerJob.type) | ||
109 | ) | ||
110 | |||
111 | return res.sendFile(getStudioTaskFilePath(filename)) | ||
112 | } | ||