]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/static.ts
Fix refreshing oauth token
[github/Chocobozzz/PeerTube.git] / server / controllers / static.ts
CommitLineData
4d4e5cd4 1import * as cors from 'cors'
50d6de9c
C
2import * as express from 'express'
3import { CONFIG, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers'
4import { VideosPreviewCache } from '../lib/cache'
eb080476 5import { asyncMiddleware } from '../middlewares'
65fcc311
C
6
7const staticRouter = express.Router()
8
9/*
60862425 10 Cors is very important to let other servers access torrent and video files
65fcc311
C
11*/
12
13const torrentsPhysicalPath = CONFIG.STORAGE.TORRENTS_DIR
14staticRouter.use(
15 STATIC_PATHS.TORRENTS,
16 cors(),
49379960 17 express.static(torrentsPhysicalPath, { maxAge: 0 }) // Don't cache because we could regenerate the torrent file
65fcc311
C
18)
19
20// Videos path for webseeding
21const videosPhysicalPath = CONFIG.STORAGE.VIDEOS_DIR
22staticRouter.use(
23 STATIC_PATHS.WEBSEED,
24 cors(),
25 express.static(videosPhysicalPath, { maxAge: STATIC_MAX_AGE })
26)
27
28// Thumbnails path for express
29const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR
30staticRouter.use(
31 STATIC_PATHS.THUMBNAILS,
32 express.static(thumbnailsPhysicalPath, { maxAge: STATIC_MAX_AGE })
33)
34
c5911fd3
C
35const avatarsPhysicalPath = CONFIG.STORAGE.AVATARS_DIR
36staticRouter.use(
37 STATIC_PATHS.AVATARS,
38 express.static(avatarsPhysicalPath, { maxAge: STATIC_MAX_AGE })
39)
40
65fcc311 41// Video previews path for express
65fcc311 42staticRouter.use(
f981dae8 43 STATIC_PATHS.PREVIEWS + ':uuid.jpg',
eb080476 44 asyncMiddleware(getPreview)
65fcc311
C
45)
46
ac235c37
RK
47// robots.txt service
48staticRouter.get('/robots.txt', (req: express.Request, res: express.Response) => {
49 res.type('text/plain')
50 return res.send(CONFIG.INSTANCE.ROBOTS)
51})
52
65fcc311
C
53// ---------------------------------------------------------------------------
54
55export {
56 staticRouter
57}
f981dae8
C
58
59// ---------------------------------------------------------------------------
60
eb080476
C
61async function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) {
62 const path = await VideosPreviewCache.Instance.getPreviewPath(req.params.uuid)
63 if (!path) return res.sendStatus(404)
f981dae8 64
eb080476 65 return res.sendFile(path, { maxAge: STATIC_MAX_AGE })
f981dae8 66}