2021-08-27 08:32:44 -04:00
|
|
|
import cors from 'cors'
|
|
|
|
import express from 'express'
|
2022-10-12 10:09:02 -04:00
|
|
|
import {
|
|
|
|
asyncMiddleware,
|
|
|
|
ensureCanAccessPrivateVideoHLSFiles,
|
|
|
|
ensureCanAccessVideoPrivateWebTorrentFiles,
|
|
|
|
handleStaticError,
|
|
|
|
optionalAuthenticate
|
|
|
|
} from '@server/middlewares'
|
2022-07-13 05:13:19 -04:00
|
|
|
import { CONFIG } from '../initializers/config'
|
2022-10-12 10:09:02 -04:00
|
|
|
import { DIRECTORIES, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers/constants'
|
2017-05-15 16:22:03 -04:00
|
|
|
|
|
|
|
const staticRouter = express.Router()
|
|
|
|
|
2022-07-13 05:13:19 -04:00
|
|
|
// Cors is very important to let other servers access torrent and video files
|
2018-07-17 09:04:54 -04:00
|
|
|
staticRouter.use(cors())
|
|
|
|
|
2022-10-12 10:09:02 -04:00
|
|
|
// WebTorrent/Classic videos
|
|
|
|
staticRouter.use(
|
|
|
|
STATIC_PATHS.PRIVATE_WEBSEED,
|
|
|
|
optionalAuthenticate,
|
|
|
|
asyncMiddleware(ensureCanAccessVideoPrivateWebTorrentFiles),
|
|
|
|
express.static(DIRECTORIES.VIDEOS.PRIVATE, { fallthrough: false }),
|
|
|
|
handleStaticError
|
|
|
|
)
|
2017-05-15 16:22:03 -04:00
|
|
|
staticRouter.use(
|
|
|
|
STATIC_PATHS.WEBSEED,
|
2022-10-12 10:09:02 -04:00
|
|
|
express.static(DIRECTORIES.VIDEOS.PUBLIC, { fallthrough: false }),
|
2022-07-13 05:21:19 -04:00
|
|
|
handleStaticError
|
2017-05-15 16:22:03 -04:00
|
|
|
)
|
2022-10-12 10:09:02 -04:00
|
|
|
|
2018-12-04 10:02:49 -05:00
|
|
|
staticRouter.use(
|
2018-12-04 11:08:55 -05:00
|
|
|
STATIC_PATHS.REDUNDANCY,
|
2022-07-13 05:21:19 -04:00
|
|
|
express.static(CONFIG.STORAGE.REDUNDANCY_DIR, { fallthrough: false }),
|
|
|
|
handleStaticError
|
2018-12-04 10:02:49 -05:00
|
|
|
)
|
|
|
|
|
2019-01-29 02:37:25 -05:00
|
|
|
// HLS
|
2022-10-12 10:09:02 -04:00
|
|
|
staticRouter.use(
|
|
|
|
STATIC_PATHS.STREAMING_PLAYLISTS.PRIVATE_HLS,
|
|
|
|
optionalAuthenticate,
|
|
|
|
asyncMiddleware(ensureCanAccessPrivateVideoHLSFiles),
|
|
|
|
express.static(DIRECTORIES.HLS_STREAMING_PLAYLIST.PRIVATE, { fallthrough: false }),
|
|
|
|
handleStaticError
|
|
|
|
)
|
2019-01-29 02:37:25 -05:00
|
|
|
staticRouter.use(
|
2019-03-05 06:00:31 -05:00
|
|
|
STATIC_PATHS.STREAMING_PLAYLISTS.HLS,
|
2022-10-12 10:09:02 -04:00
|
|
|
express.static(DIRECTORIES.HLS_STREAMING_PLAYLIST.PUBLIC, { fallthrough: false }),
|
2022-07-13 05:21:19 -04:00
|
|
|
handleStaticError
|
2019-01-29 02:37:25 -05:00
|
|
|
)
|
|
|
|
|
2017-05-15 16:22:03 -04:00
|
|
|
// Thumbnails path for express
|
|
|
|
const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR
|
|
|
|
staticRouter.use(
|
|
|
|
STATIC_PATHS.THUMBNAILS,
|
2022-07-13 05:21:19 -04:00
|
|
|
express.static(thumbnailsPhysicalPath, { maxAge: STATIC_MAX_AGE.SERVER, fallthrough: false }),
|
|
|
|
handleStaticError
|
2017-05-15 16:22:03 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
staticRouter
|
|
|
|
}
|