diff options
Diffstat (limited to 'server/controllers/static.ts')
-rw-r--r-- | server/controllers/static.ts | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/server/controllers/static.ts b/server/controllers/static.ts index 33c429eb1..6ef9154b9 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts | |||
@@ -1,30 +1,63 @@ | |||
1 | import cors from 'cors' | 1 | import cors from 'cors' |
2 | import express from 'express' | 2 | import express from 'express' |
3 | import { handleStaticError } from '@server/middlewares' | 3 | import { |
4 | asyncMiddleware, | ||
5 | ensureCanAccessPrivateVideoHLSFiles, | ||
6 | ensureCanAccessVideoPrivateWebTorrentFiles, | ||
7 | handleStaticError, | ||
8 | optionalAuthenticate | ||
9 | } from '@server/middlewares' | ||
4 | import { CONFIG } from '../initializers/config' | 10 | import { CONFIG } from '../initializers/config' |
5 | import { HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers/constants' | 11 | import { DIRECTORIES, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers/constants' |
6 | 12 | ||
7 | const staticRouter = express.Router() | 13 | const staticRouter = express.Router() |
8 | 14 | ||
9 | // Cors is very important to let other servers access torrent and video files | 15 | // Cors is very important to let other servers access torrent and video files |
10 | staticRouter.use(cors()) | 16 | staticRouter.use(cors()) |
11 | 17 | ||
12 | // Videos path for webseed | 18 | // --------------------------------------------------------------------------- |
19 | // WebTorrent/Classic videos | ||
20 | // --------------------------------------------------------------------------- | ||
21 | |||
22 | const privateWebTorrentStaticMiddlewares = CONFIG.STATIC_FILES.PRIVATE_FILES_REQUIRE_AUTH === true | ||
23 | ? [ optionalAuthenticate, asyncMiddleware(ensureCanAccessVideoPrivateWebTorrentFiles) ] | ||
24 | : [] | ||
25 | |||
26 | staticRouter.use( | ||
27 | STATIC_PATHS.PRIVATE_WEBSEED, | ||
28 | ...privateWebTorrentStaticMiddlewares, | ||
29 | express.static(DIRECTORIES.VIDEOS.PRIVATE, { fallthrough: false }), | ||
30 | handleStaticError | ||
31 | ) | ||
13 | staticRouter.use( | 32 | staticRouter.use( |
14 | STATIC_PATHS.WEBSEED, | 33 | STATIC_PATHS.WEBSEED, |
15 | express.static(CONFIG.STORAGE.VIDEOS_DIR, { fallthrough: false }), | 34 | express.static(DIRECTORIES.VIDEOS.PUBLIC, { fallthrough: false }), |
16 | handleStaticError | 35 | handleStaticError |
17 | ) | 36 | ) |
37 | |||
18 | staticRouter.use( | 38 | staticRouter.use( |
19 | STATIC_PATHS.REDUNDANCY, | 39 | STATIC_PATHS.REDUNDANCY, |
20 | express.static(CONFIG.STORAGE.REDUNDANCY_DIR, { fallthrough: false }), | 40 | express.static(CONFIG.STORAGE.REDUNDANCY_DIR, { fallthrough: false }), |
21 | handleStaticError | 41 | handleStaticError |
22 | ) | 42 | ) |
23 | 43 | ||
44 | // --------------------------------------------------------------------------- | ||
24 | // HLS | 45 | // HLS |
46 | // --------------------------------------------------------------------------- | ||
47 | |||
48 | const privateHLSStaticMiddlewares = CONFIG.STATIC_FILES.PRIVATE_FILES_REQUIRE_AUTH === true | ||
49 | ? [ optionalAuthenticate, asyncMiddleware(ensureCanAccessPrivateVideoHLSFiles) ] | ||
50 | : [] | ||
51 | |||
52 | staticRouter.use( | ||
53 | STATIC_PATHS.STREAMING_PLAYLISTS.PRIVATE_HLS, | ||
54 | ...privateHLSStaticMiddlewares, | ||
55 | express.static(DIRECTORIES.HLS_STREAMING_PLAYLIST.PRIVATE, { fallthrough: false }), | ||
56 | handleStaticError | ||
57 | ) | ||
25 | staticRouter.use( | 58 | staticRouter.use( |
26 | STATIC_PATHS.STREAMING_PLAYLISTS.HLS, | 59 | STATIC_PATHS.STREAMING_PLAYLISTS.HLS, |
27 | express.static(HLS_STREAMING_PLAYLIST_DIRECTORY, { fallthrough: false }), | 60 | express.static(DIRECTORIES.HLS_STREAMING_PLAYLIST.PUBLIC, { fallthrough: false }), |
28 | handleStaticError | 61 | handleStaticError |
29 | ) | 62 | ) |
30 | 63 | ||