2022-10-19 03:43:53 -05:00
|
|
|
import cors from 'cors'
|
|
|
|
import express from 'express'
|
|
|
|
import { OBJECT_STORAGE_PROXY_PATHS } from '@server/initializers/constants'
|
2023-07-11 02:21:13 -05:00
|
|
|
import { proxifyHLS, proxifyWebVideoFile } from '@server/lib/object-storage'
|
2022-10-19 03:43:53 -05:00
|
|
|
import {
|
|
|
|
asyncMiddleware,
|
|
|
|
ensureCanAccessPrivateVideoHLSFiles,
|
2023-07-11 02:21:13 -05:00
|
|
|
ensureCanAccessVideoPrivateWebVideoFiles,
|
2022-10-26 09:23:39 -05:00
|
|
|
ensurePrivateObjectStorageProxyIsEnabled,
|
2022-10-19 03:43:53 -05:00
|
|
|
optionalAuthenticate
|
|
|
|
} from '@server/middlewares'
|
2023-04-21 07:55:10 -05:00
|
|
|
import { doReinjectVideoFileToken } from './shared/m3u8-playlist'
|
2022-10-19 03:43:53 -05:00
|
|
|
|
|
|
|
const objectStorageProxyRouter = express.Router()
|
|
|
|
|
|
|
|
objectStorageProxyRouter.use(cors())
|
|
|
|
|
2023-07-11 04:39:59 -05:00
|
|
|
objectStorageProxyRouter.get(
|
|
|
|
[ OBJECT_STORAGE_PROXY_PATHS.PRIVATE_WEB_VIDEOS + ':filename', OBJECT_STORAGE_PROXY_PATHS.LEGACY_PRIVATE_WEB_VIDEOS + ':filename' ],
|
2022-10-26 09:23:39 -05:00
|
|
|
ensurePrivateObjectStorageProxyIsEnabled,
|
2022-10-19 03:43:53 -05:00
|
|
|
optionalAuthenticate,
|
2023-07-11 02:21:13 -05:00
|
|
|
asyncMiddleware(ensureCanAccessVideoPrivateWebVideoFiles),
|
|
|
|
asyncMiddleware(proxifyWebVideoController)
|
2022-10-19 03:43:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
objectStorageProxyRouter.get(OBJECT_STORAGE_PROXY_PATHS.STREAMING_PLAYLISTS.PRIVATE_HLS + ':videoUUID/:filename',
|
2022-10-26 09:23:39 -05:00
|
|
|
ensurePrivateObjectStorageProxyIsEnabled,
|
2022-10-19 03:43:53 -05:00
|
|
|
optionalAuthenticate,
|
|
|
|
asyncMiddleware(ensureCanAccessPrivateVideoHLSFiles),
|
2023-04-21 07:55:10 -05:00
|
|
|
asyncMiddleware(proxifyHLSController)
|
2022-10-19 03:43:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
objectStorageProxyRouter
|
|
|
|
}
|
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
function proxifyWebVideoController (req: express.Request, res: express.Response) {
|
2022-10-19 03:43:53 -05:00
|
|
|
const filename = req.params.filename
|
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
return proxifyWebVideoFile({ req, res, filename })
|
2022-10-19 03:43:53 -05:00
|
|
|
}
|
|
|
|
|
2023-04-21 07:55:10 -05:00
|
|
|
function proxifyHLSController (req: express.Request, res: express.Response) {
|
2022-10-19 03:43:53 -05:00
|
|
|
const playlist = res.locals.videoStreamingPlaylist
|
|
|
|
const video = res.locals.onlyVideo
|
|
|
|
const filename = req.params.filename
|
|
|
|
|
2023-04-21 07:55:10 -05:00
|
|
|
const reinjectVideoFileToken = filename.endsWith('.m3u8') && doReinjectVideoFileToken(req)
|
2022-12-02 07:47:21 -06:00
|
|
|
|
2023-04-21 07:55:10 -05:00
|
|
|
return proxifyHLS({
|
|
|
|
req,
|
|
|
|
res,
|
|
|
|
playlist,
|
|
|
|
video,
|
|
|
|
filename,
|
|
|
|
reinjectVideoFileToken
|
2022-10-19 03:43:53 -05:00
|
|
|
})
|
|
|
|
}
|