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: STATIC_MAX_AGE })
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
40 const previewsPhysicalPath = CONFIG.STORAGE.PREVIEWS_DIR
42 STATIC_PATHS.PREVIEWS + ':uuid.jpg',
46 // ---------------------------------------------------------------------------
52 // ---------------------------------------------------------------------------
54 function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) {
55 VideosPreviewCache.Instance.getPreviewPath(req.params.uuid)
57 if (!path) return res.sendStatus(404)
59 return res.sendFile(path, { maxAge: STATIC_MAX_AGE })