]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/controllers/static.ts
Fix tests and user quota
[github/Chocobozzz/PeerTube.git] / server / controllers / static.ts
... / ...
CommitLineData
1import * as express from 'express'
2import * as cors from 'cors'
3
4import {
5 CONFIG,
6 STATIC_MAX_AGE,
7 STATIC_PATHS
8} from '../initializers'
9import { VideosPreviewCache } from '../lib'
10
11const staticRouter = express.Router()
12
13/*
14 Cors is very important to let other pods access torrent and video files
15*/
16
17const torrentsPhysicalPath = CONFIG.STORAGE.TORRENTS_DIR
18staticRouter.use(
19 STATIC_PATHS.TORRENTS,
20 cors(),
21 express.static(torrentsPhysicalPath, { maxAge: STATIC_MAX_AGE })
22)
23
24// Videos path for webseeding
25const videosPhysicalPath = CONFIG.STORAGE.VIDEOS_DIR
26staticRouter.use(
27 STATIC_PATHS.WEBSEED,
28 cors(),
29 express.static(videosPhysicalPath, { maxAge: STATIC_MAX_AGE })
30)
31
32// Thumbnails path for express
33const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR
34staticRouter.use(
35 STATIC_PATHS.THUMBNAILS,
36 express.static(thumbnailsPhysicalPath, { maxAge: STATIC_MAX_AGE })
37)
38
39// Video previews path for express
40staticRouter.use(
41 STATIC_PATHS.PREVIEWS + ':uuid.jpg',
42 getPreview
43)
44
45// ---------------------------------------------------------------------------
46
47export {
48 staticRouter
49}
50
51// ---------------------------------------------------------------------------
52
53function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) {
54 VideosPreviewCache.Instance.getPreviewPath(req.params.uuid)
55 .then(path => {
56 if (!path) return res.sendStatus(404)
57
58 return res.sendFile(path, { maxAge: STATIC_MAX_AGE })
59 })
60}