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