]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/object-storage-proxy.ts
Translated using Weblate (Vietnamese)
[github/Chocobozzz/PeerTube.git] / server / controllers / object-storage-proxy.ts
CommitLineData
9ab330b9
C
1import cors from 'cors'
2import express from 'express'
3import { OBJECT_STORAGE_PROXY_PATHS } from '@server/initializers/constants'
0c9668f7 4import { proxifyHLS, proxifyWebTorrentFile } from '@server/lib/object-storage'
9ab330b9
C
5import {
6 asyncMiddleware,
7 ensureCanAccessPrivateVideoHLSFiles,
8 ensureCanAccessVideoPrivateWebTorrentFiles,
5a122ddd 9 ensurePrivateObjectStorageProxyIsEnabled,
9ab330b9
C
10 optionalAuthenticate
11} from '@server/middlewares'
0c9668f7 12import { doReinjectVideoFileToken } from './shared/m3u8-playlist'
9ab330b9
C
13
14const objectStorageProxyRouter = express.Router()
15
16objectStorageProxyRouter.use(cors())
17
18objectStorageProxyRouter.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
25objectStorageProxyRouter.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
34export {
35 objectStorageProxyRouter
36}
37
0c9668f7 38function 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 44function 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}