]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/controllers/static.ts
Put private videos under a specific subdirectory
[github/Chocobozzz/PeerTube.git] / server / controllers / static.ts
1 import cors from 'cors'
2 import express from 'express'
3 import {
4 asyncMiddleware,
5 ensureCanAccessPrivateVideoHLSFiles,
6 ensureCanAccessVideoPrivateWebTorrentFiles,
7 handleStaticError,
8 optionalAuthenticate
9 } from '@server/middlewares'
10 import { CONFIG } from '../initializers/config'
11 import { DIRECTORIES, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers/constants'
12
13 const staticRouter = express.Router()
14
15 // Cors is very important to let other servers access torrent and video files
16 staticRouter.use(cors())
17
18 // WebTorrent/Classic videos
19 staticRouter.use(
20 STATIC_PATHS.PRIVATE_WEBSEED,
21 optionalAuthenticate,
22 asyncMiddleware(ensureCanAccessVideoPrivateWebTorrentFiles),
23 express.static(DIRECTORIES.VIDEOS.PRIVATE, { fallthrough: false }),
24 handleStaticError
25 )
26 staticRouter.use(
27 STATIC_PATHS.WEBSEED,
28 express.static(DIRECTORIES.VIDEOS.PUBLIC, { fallthrough: false }),
29 handleStaticError
30 )
31
32 staticRouter.use(
33 STATIC_PATHS.REDUNDANCY,
34 express.static(CONFIG.STORAGE.REDUNDANCY_DIR, { fallthrough: false }),
35 handleStaticError
36 )
37
38 // HLS
39 staticRouter.use(
40 STATIC_PATHS.STREAMING_PLAYLISTS.PRIVATE_HLS,
41 optionalAuthenticate,
42 asyncMiddleware(ensureCanAccessPrivateVideoHLSFiles),
43 express.static(DIRECTORIES.HLS_STREAMING_PLAYLIST.PRIVATE, { fallthrough: false }),
44 handleStaticError
45 )
46 staticRouter.use(
47 STATIC_PATHS.STREAMING_PLAYLISTS.HLS,
48 express.static(DIRECTORIES.HLS_STREAMING_PLAYLIST.PUBLIC, { fallthrough: false }),
49 handleStaticError
50 )
51
52 // Thumbnails path for express
53 const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR
54 staticRouter.use(
55 STATIC_PATHS.THUMBNAILS,
56 express.static(thumbnailsPhysicalPath, { maxAge: STATIC_MAX_AGE.SERVER, fallthrough: false }),
57 handleStaticError
58 )
59
60 // ---------------------------------------------------------------------------
61
62 export {
63 staticRouter
64 }