PeerTube/server/controllers/static.ts

65 lines
1.8 KiB
TypeScript
Raw Normal View History

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