aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/static.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/static.ts')
-rw-r--r--server/controllers/static.ts38
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 @@
1import * as cors from 'cors' 1import * as cors from 'cors'
2import * as express from 'express' 2import * as express from 'express'
3import { CONFIG, ROUTE_CACHE_LIFETIME, STATIC_DOWNLOAD_PATHS, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers' 3import {
4import { 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'
11import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache'
5import { cacheRoute } from '../middlewares/cache' 12import { cacheRoute } from '../middlewares/cache'
6import { asyncMiddleware, videosGetValidator } from '../middlewares' 13import { asyncMiddleware, videosGetValidator } from '../middlewares'
7import { VideoModel } from '../models/video/video' 14import { VideoModel } from '../models/video/video'
8import { VideosCaptionCache } from '../lib/cache/videos-caption-cache'
9import { UserModel } from '../models/account/user' 15import { UserModel } from '../models/account/user'
10import { VideoCommentModel } from '../models/video/video-comment' 16import { VideoCommentModel } from '../models/video/video-comment'
11import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo' 17import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo'
12import { join } from 'path' 18import { join } from 'path'
13import { root } from '../helpers/core-utils' 19import { root } from '../helpers/core-utils'
20import { CONFIG } from '../initializers/config'
14 21
15const packageJSON = require('../../../package.json') 22const packageJSON = require('../../../package.json')
16const staticRouter = express.Router() 23const staticRouter = express.Router()
@@ -51,6 +58,13 @@ staticRouter.use(
51 asyncMiddleware(downloadVideoFile) 58 asyncMiddleware(downloadVideoFile)
52) 59)
53 60
61// HLS
62staticRouter.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
55const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR 69const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR
56staticRouter.use( 70staticRouter.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
153async function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) { 167async 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
160async function getVideoCaption (req: express.Request, res: express.Response) { 174async 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
170async function generateNodeinfo (req: express.Request, res: express.Response, next: express.NextFunction) { 184async 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
232function getVideoAndFile (req: express.Request, res: express.Response) { 246function 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