diff options
Diffstat (limited to 'server/controllers/static.ts')
-rw-r--r-- | server/controllers/static.ts | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/server/controllers/static.ts b/server/controllers/static.ts index 4fd58f70c..05019fcc2 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts | |||
@@ -1,16 +1,23 @@ | |||
1 | import * as cors from 'cors' | 1 | import * as cors from 'cors' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { CONFIG, ROUTE_CACHE_LIFETIME, STATIC_DOWNLOAD_PATHS, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers' | 3 | import { |
4 | import { VideosPreviewCache } from '../lib/cache' | 4 | HLS_STREAMING_PLAYLIST_DIRECTORY, |
5 | ROUTE_CACHE_LIFETIME, | ||
6 | STATIC_DOWNLOAD_PATHS, | ||
7 | STATIC_MAX_AGE, | ||
8 | STATIC_PATHS, | ||
9 | WEBSERVER | ||
10 | } from '../initializers/constants' | ||
11 | import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache' | ||
5 | import { cacheRoute } from '../middlewares/cache' | 12 | import { cacheRoute } from '../middlewares/cache' |
6 | import { asyncMiddleware, videosGetValidator } from '../middlewares' | 13 | import { asyncMiddleware, videosGetValidator } from '../middlewares' |
7 | import { VideoModel } from '../models/video/video' | 14 | import { VideoModel } from '../models/video/video' |
8 | import { VideosCaptionCache } from '../lib/cache/videos-caption-cache' | ||
9 | import { UserModel } from '../models/account/user' | 15 | import { UserModel } from '../models/account/user' |
10 | import { VideoCommentModel } from '../models/video/video-comment' | 16 | import { VideoCommentModel } from '../models/video/video-comment' |
11 | import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo' | 17 | import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo' |
12 | import { join } from 'path' | 18 | import { join } from 'path' |
13 | import { root } from '../helpers/core-utils' | 19 | import { root } from '../helpers/core-utils' |
20 | import { CONFIG } from '../initializers/config' | ||
14 | 21 | ||
15 | const packageJSON = require('../../../package.json') | 22 | const packageJSON = require('../../../package.json') |
16 | const staticRouter = express.Router() | 23 | const staticRouter = express.Router() |
@@ -51,6 +58,13 @@ staticRouter.use( | |||
51 | asyncMiddleware(downloadVideoFile) | 58 | asyncMiddleware(downloadVideoFile) |
52 | ) | 59 | ) |
53 | 60 | ||
61 | // HLS | ||
62 | staticRouter.use( | ||
63 | STATIC_PATHS.STREAMING_PLAYLISTS.HLS, | ||
64 | cors(), | ||
65 | express.static(HLS_STREAMING_PLAYLIST_DIRECTORY, { fallthrough: false }) // 404 if the file does not exist | ||
66 | ) | ||
67 | |||
54 | // Thumbnails path for express | 68 | // Thumbnails path for express |
55 | const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR | 69 | const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR |
56 | staticRouter.use( | 70 | staticRouter.use( |
@@ -108,7 +122,7 @@ staticRouter.use('/.well-known/nodeinfo', | |||
108 | links: [ | 122 | links: [ |
109 | { | 123 | { |
110 | rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0', | 124 | rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0', |
111 | href: CONFIG.WEBSERVER.URL + '/nodeinfo/2.0.json' | 125 | href: WEBSERVER.URL + '/nodeinfo/2.0.json' |
112 | } | 126 | } |
113 | ] | 127 | ] |
114 | }) | 128 | }) |
@@ -150,21 +164,21 @@ export { | |||
150 | 164 | ||
151 | // --------------------------------------------------------------------------- | 165 | // --------------------------------------------------------------------------- |
152 | 166 | ||
153 | async function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) { | 167 | async function getPreview (req: express.Request, res: express.Response) { |
154 | const path = await VideosPreviewCache.Instance.getFilePath(req.params.uuid) | 168 | const result = await VideosPreviewCache.Instance.getFilePath(req.params.uuid) |
155 | if (!path) return res.sendStatus(404) | 169 | if (!result) return res.sendStatus(404) |
156 | 170 | ||
157 | return res.sendFile(path, { maxAge: STATIC_MAX_AGE }) | 171 | return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE }) |
158 | } | 172 | } |
159 | 173 | ||
160 | async function getVideoCaption (req: express.Request, res: express.Response) { | 174 | async function getVideoCaption (req: express.Request, res: express.Response) { |
161 | const path = await VideosCaptionCache.Instance.getFilePath({ | 175 | const result = await VideosCaptionCache.Instance.getFilePath({ |
162 | videoId: req.params.videoId, | 176 | videoId: req.params.videoId, |
163 | language: req.params.captionLanguage | 177 | language: req.params.captionLanguage |
164 | }) | 178 | }) |
165 | if (!path) return res.sendStatus(404) | 179 | if (!result) return res.sendStatus(404) |
166 | 180 | ||
167 | return res.sendFile(path, { maxAge: STATIC_MAX_AGE }) | 181 | return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE }) |
168 | } | 182 | } |
169 | 183 | ||
170 | async function generateNodeinfo (req: express.Request, res: express.Response, next: express.NextFunction) { | 184 | async function generateNodeinfo (req: express.Request, res: express.Response, next: express.NextFunction) { |
@@ -231,7 +245,7 @@ async function downloadVideoFile (req: express.Request, res: express.Response, n | |||
231 | 245 | ||
232 | function getVideoAndFile (req: express.Request, res: express.Response) { | 246 | function getVideoAndFile (req: express.Request, res: express.Response) { |
233 | const resolution = parseInt(req.params.resolution, 10) | 247 | const resolution = parseInt(req.params.resolution, 10) |
234 | const video: VideoModel = res.locals.video | 248 | const video = res.locals.video |
235 | 249 | ||
236 | const videoFile = video.VideoFiles.find(f => f.resolution === resolution) | 250 | const videoFile = video.VideoFiles.find(f => f.resolution === resolution) |
237 | 251 | ||