aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/lazy-static.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/lazy-static.ts')
-rw-r--r--server/controllers/lazy-static.ts23
1 files changed, 18 insertions, 5 deletions
diff --git a/server/controllers/lazy-static.ts b/server/controllers/lazy-static.ts
index 656dea223..c2f5c7b56 100644
--- a/server/controllers/lazy-static.ts
+++ b/server/controllers/lazy-static.ts
@@ -1,12 +1,13 @@
1import * as cors from 'cors' 1import * as cors from 'cors'
2import * as express from 'express' 2import * as express from 'express'
3import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache'
4import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
5import { logger } from '../helpers/logger'
3import { LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants' 6import { LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants'
7import { avatarPathUnsafeCache, pushAvatarProcessInQueue } from '../lib/avatar'
4import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache' 8import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache'
5import { asyncMiddleware } from '../middlewares' 9import { asyncMiddleware } from '../middlewares'
6import { AvatarModel } from '../models/avatar/avatar' 10import { AvatarModel } from '../models/avatar/avatar'
7import { logger } from '../helpers/logger'
8import { avatarPathUnsafeCache, pushAvatarProcessInQueue } from '../lib/avatar'
9import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
10 11
11const lazyStaticRouter = express.Router() 12const lazyStaticRouter = express.Router()
12 13
@@ -27,6 +28,11 @@ lazyStaticRouter.use(
27 asyncMiddleware(getVideoCaption) 28 asyncMiddleware(getVideoCaption)
28) 29)
29 30
31lazyStaticRouter.use(
32 LAZY_STATIC_PATHS.TORRENTS + ':filename',
33 asyncMiddleware(getTorrent)
34)
35
30// --------------------------------------------------------------------------- 36// ---------------------------------------------------------------------------
31 37
32export { 38export {
@@ -67,19 +73,26 @@ async function getAvatar (req: express.Request, res: express.Response) {
67 const path = avatar.getPath() 73 const path = avatar.getPath()
68 74
69 avatarPathUnsafeCache.set(filename, path) 75 avatarPathUnsafeCache.set(filename, path)
70 return res.sendFile(path, { maxAge: STATIC_MAX_AGE.SERVER }) 76 return res.sendFile(path, { maxAge: STATIC_MAX_AGE.LAZY_SERVER })
71} 77}
72 78
73async function getPreview (req: express.Request, res: express.Response) { 79async function getPreview (req: express.Request, res: express.Response) {
74 const result = await VideosPreviewCache.Instance.getFilePath(req.params.filename) 80 const result = await VideosPreviewCache.Instance.getFilePath(req.params.filename)
75 if (!result) return res.sendStatus(HttpStatusCode.NOT_FOUND_404) 81 if (!result) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
76 82
77 return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.SERVER }) 83 return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.LAZY_SERVER })
78} 84}
79 85
80async function getVideoCaption (req: express.Request, res: express.Response) { 86async function getVideoCaption (req: express.Request, res: express.Response) {
81 const result = await VideosCaptionCache.Instance.getFilePath(req.params.filename) 87 const result = await VideosCaptionCache.Instance.getFilePath(req.params.filename)
82 if (!result) return res.sendStatus(HttpStatusCode.NOT_FOUND_404) 88 if (!result) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
83 89
90 return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.LAZY_SERVER })
91}
92
93async function getTorrent (req: express.Request, res: express.Response) {
94 const result = await VideosTorrentCache.Instance.getFilePath(req.params.filename)
95 if (!result) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
96
84 return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.SERVER }) 97 return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.SERVER })
85} 98}