2022-10-19 10:43:53 +02:00
|
|
|
import cors from 'cors'
|
|
|
|
import express from 'express'
|
|
|
|
import { OBJECT_STORAGE_PROXY_PATHS } from '@server/initializers/constants'
|
2023-04-21 14:55:10 +02:00
|
|
|
import { proxifyHLS, proxifyWebTorrentFile } from '@server/lib/object-storage'
|
2022-10-19 10:43:53 +02:00
|
|
|
import {
|
|
|
|
asyncMiddleware,
|
|
|
|
ensureCanAccessPrivateVideoHLSFiles,
|
|
|
|
ensureCanAccessVideoPrivateWebTorrentFiles,
|
2022-10-26 16:23:39 +02:00
|
|
|
ensurePrivateObjectStorageProxyIsEnabled,
|
2022-10-19 10:43:53 +02:00
|
|
|
optionalAuthenticate
|
|
|
|
} from '@server/middlewares'
|
2023-04-21 14:55:10 +02:00
|
|
|
import { doReinjectVideoFileToken } from './shared/m3u8-playlist'
|
2022-10-19 10:43:53 +02:00
|
|
|
|
|
|
|
const objectStorageProxyRouter = express.Router()
|
|
|
|
|
|
|
|
objectStorageProxyRouter.use(cors())
|
|
|
|
|
|
|
|
objectStorageProxyRouter.get(OBJECT_STORAGE_PROXY_PATHS.PRIVATE_WEBSEED + ':filename',
|
2022-10-26 16:23:39 +02:00
|
|
|
ensurePrivateObjectStorageProxyIsEnabled,
|
2022-10-19 10:43:53 +02:00
|
|
|
optionalAuthenticate,
|
|
|
|
asyncMiddleware(ensureCanAccessVideoPrivateWebTorrentFiles),
|
2023-04-21 14:55:10 +02:00
|
|
|
asyncMiddleware(proxifyWebTorrentController)
|
2022-10-19 10:43:53 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
objectStorageProxyRouter.get(OBJECT_STORAGE_PROXY_PATHS.STREAMING_PLAYLISTS.PRIVATE_HLS + ':videoUUID/:filename',
|
2022-10-26 16:23:39 +02:00
|
|
|
ensurePrivateObjectStorageProxyIsEnabled,
|
2022-10-19 10:43:53 +02:00
|
|
|
optionalAuthenticate,
|
|
|
|
asyncMiddleware(ensureCanAccessPrivateVideoHLSFiles),
|
2023-04-21 14:55:10 +02:00
|
|
|
asyncMiddleware(proxifyHLSController)
|
2022-10-19 10:43:53 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
objectStorageProxyRouter
|
|
|
|
}
|
|
|
|
|
2023-04-21 14:55:10 +02:00
|
|
|
function proxifyWebTorrentController (req: express.Request, res: express.Response) {
|
2022-10-19 10:43:53 +02:00
|
|
|
const filename = req.params.filename
|
|
|
|
|
2023-04-21 14:55:10 +02:00
|
|
|
return proxifyWebTorrentFile({ req, res, filename })
|
2022-10-19 10:43:53 +02:00
|
|
|
}
|
|
|
|
|
2023-04-21 14:55:10 +02:00
|
|
|
function proxifyHLSController (req: express.Request, res: express.Response) {
|
2022-10-19 10:43:53 +02:00
|
|
|
const playlist = res.locals.videoStreamingPlaylist
|
|
|
|
const video = res.locals.onlyVideo
|
|
|
|
const filename = req.params.filename
|
|
|
|
|
2023-04-21 14:55:10 +02:00
|
|
|
const reinjectVideoFileToken = filename.endsWith('.m3u8') && doReinjectVideoFileToken(req)
|
2022-12-02 14:47:21 +01:00
|
|
|
|
2023-04-21 14:55:10 +02:00
|
|
|
return proxifyHLS({
|
|
|
|
req,
|
|
|
|
res,
|
|
|
|
playlist,
|
|
|
|
video,
|
|
|
|
filename,
|
|
|
|
reinjectVideoFileToken
|
2022-10-19 10:43:53 +02:00
|
|
|
})
|
|
|
|
}
|