ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

61 lines
1.9 KiB

  1. import cors from 'cors'
  2. import express from 'express'
  3. import { OBJECT_STORAGE_PROXY_PATHS } from '@server/initializers/constants.js'
  4. import { proxifyHLS, proxifyWebVideoFile } from '@server/lib/object-storage/index.js'
  5. import {
  6. asyncMiddleware,
  7. ensureCanAccessPrivateVideoHLSFiles,
  8. ensureCanAccessVideoPrivateWebVideoFiles,
  9. ensurePrivateObjectStorageProxyIsEnabled,
  10. optionalAuthenticate
  11. } from '@server/middlewares/index.js'
  12. import { doReinjectVideoFileToken } from './shared/m3u8-playlist.js'
  13. const objectStorageProxyRouter = express.Router()
  14. objectStorageProxyRouter.use(cors())
  15. objectStorageProxyRouter.get(
  16. [ OBJECT_STORAGE_PROXY_PATHS.PRIVATE_WEB_VIDEOS + ':filename', OBJECT_STORAGE_PROXY_PATHS.LEGACY_PRIVATE_WEB_VIDEOS + ':filename' ],
  17. ensurePrivateObjectStorageProxyIsEnabled,
  18. optionalAuthenticate,
  19. asyncMiddleware(ensureCanAccessVideoPrivateWebVideoFiles),
  20. asyncMiddleware(proxifyWebVideoController)
  21. )
  22. objectStorageProxyRouter.get(OBJECT_STORAGE_PROXY_PATHS.STREAMING_PLAYLISTS.PRIVATE_HLS + ':videoUUID/:filename',
  23. ensurePrivateObjectStorageProxyIsEnabled,
  24. optionalAuthenticate,
  25. asyncMiddleware(ensureCanAccessPrivateVideoHLSFiles),
  26. asyncMiddleware(proxifyHLSController)
  27. )
  28. // ---------------------------------------------------------------------------
  29. export {
  30. objectStorageProxyRouter
  31. }
  32. function proxifyWebVideoController (req: express.Request, res: express.Response) {
  33. const filename = req.params.filename
  34. return proxifyWebVideoFile({ req, res, filename })
  35. }
  36. function proxifyHLSController (req: express.Request, res: express.Response) {
  37. const playlist = res.locals.videoStreamingPlaylist
  38. const video = res.locals.onlyVideo
  39. const filename = req.params.filename
  40. const reinjectVideoFileToken = filename.endsWith('.m3u8') && doReinjectVideoFileToken(req)
  41. return proxifyHLS({
  42. req,
  43. res,
  44. playlist,
  45. video,
  46. filename,
  47. reinjectVideoFileToken
  48. })
  49. }