]>
Commit | Line | Data |
---|---|---|
9ab330b9 C |
1 | import cors from 'cors' |
2 | import express from 'express' | |
3 | import { OBJECT_STORAGE_PROXY_PATHS } from '@server/initializers/constants' | |
0c9668f7 | 4 | import { proxifyHLS, proxifyWebTorrentFile } from '@server/lib/object-storage' |
9ab330b9 C |
5 | import { |
6 | asyncMiddleware, | |
7 | ensureCanAccessPrivateVideoHLSFiles, | |
8 | ensureCanAccessVideoPrivateWebTorrentFiles, | |
5a122ddd | 9 | ensurePrivateObjectStorageProxyIsEnabled, |
9ab330b9 C |
10 | optionalAuthenticate |
11 | } from '@server/middlewares' | |
0c9668f7 | 12 | import { doReinjectVideoFileToken } from './shared/m3u8-playlist' |
9ab330b9 C |
13 | |
14 | const objectStorageProxyRouter = express.Router() | |
15 | ||
16 | objectStorageProxyRouter.use(cors()) | |
17 | ||
18 | objectStorageProxyRouter.get(OBJECT_STORAGE_PROXY_PATHS.PRIVATE_WEBSEED + ':filename', | |
5a122ddd | 19 | ensurePrivateObjectStorageProxyIsEnabled, |
9ab330b9 C |
20 | optionalAuthenticate, |
21 | asyncMiddleware(ensureCanAccessVideoPrivateWebTorrentFiles), | |
0c9668f7 | 22 | asyncMiddleware(proxifyWebTorrentController) |
9ab330b9 C |
23 | ) |
24 | ||
25 | objectStorageProxyRouter.get(OBJECT_STORAGE_PROXY_PATHS.STREAMING_PLAYLISTS.PRIVATE_HLS + ':videoUUID/:filename', | |
5a122ddd | 26 | ensurePrivateObjectStorageProxyIsEnabled, |
9ab330b9 C |
27 | optionalAuthenticate, |
28 | asyncMiddleware(ensureCanAccessPrivateVideoHLSFiles), | |
0c9668f7 | 29 | asyncMiddleware(proxifyHLSController) |
9ab330b9 C |
30 | ) |
31 | ||
32 | // --------------------------------------------------------------------------- | |
33 | ||
34 | export { | |
35 | objectStorageProxyRouter | |
36 | } | |
37 | ||
0c9668f7 | 38 | function proxifyWebTorrentController (req: express.Request, res: express.Response) { |
9ab330b9 C |
39 | const filename = req.params.filename |
40 | ||
0c9668f7 | 41 | return proxifyWebTorrentFile({ req, res, filename }) |
9ab330b9 C |
42 | } |
43 | ||
0c9668f7 | 44 | function proxifyHLSController (req: express.Request, res: express.Response) { |
9ab330b9 C |
45 | const playlist = res.locals.videoStreamingPlaylist |
46 | const video = res.locals.onlyVideo | |
47 | const filename = req.params.filename | |
48 | ||
0c9668f7 | 49 | const reinjectVideoFileToken = filename.endsWith('.m3u8') && doReinjectVideoFileToken(req) |
71e3e879 | 50 | |
0c9668f7 C |
51 | return proxifyHLS({ |
52 | req, | |
53 | res, | |
54 | playlist, | |
55 | video, | |
56 | filename, | |
57 | reinjectVideoFileToken | |
9ab330b9 C |
58 | }) |
59 | } |