1 import * as express from 'express'
2 import * as cors from 'cors'
8 } from '../initializers'
9 import { VideosPreviewCache } from '../lib'
11 const staticRouter = express.Router()
14 Cors is very important to let other pods access torrent and video files
17 const torrentsPhysicalPath = CONFIG.STORAGE.TORRENTS_DIR
19 STATIC_PATHS.TORRENTS,
21 express.static(torrentsPhysicalPath, { maxAge: 0 }) // Don't cache because we could regenerate the torrent file
24 // Videos path for webseeding
25 const videosPhysicalPath = CONFIG.STORAGE.VIDEOS_DIR
29 express.static(videosPhysicalPath, { maxAge: STATIC_MAX_AGE })
32 // Thumbnails path for express
33 const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR
35 STATIC_PATHS.THUMBNAILS,
36 express.static(thumbnailsPhysicalPath, { maxAge: STATIC_MAX_AGE })
39 // Video previews path for express
41 STATIC_PATHS.PREVIEWS + ':uuid.jpg',
45 // ---------------------------------------------------------------------------
51 // ---------------------------------------------------------------------------
53 function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) {
54 VideosPreviewCache.Instance.getPreviewPath(req.params.uuid)
56 if (!path) return res.sendStatus(404)
58 return res.sendFile(path, { maxAge: STATIC_MAX_AGE })