diff options
Diffstat (limited to 'server/controllers/lazy-static.ts')
-rw-r--r-- | server/controllers/lazy-static.ts | 23 |
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 @@ | |||
1 | import * as cors from 'cors' | 1 | import * as cors from 'cors' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache' | ||
4 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | ||
5 | import { logger } from '../helpers/logger' | ||
3 | import { LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants' | 6 | import { LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants' |
7 | import { avatarPathUnsafeCache, pushAvatarProcessInQueue } from '../lib/avatar' | ||
4 | import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache' | 8 | import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache' |
5 | import { asyncMiddleware } from '../middlewares' | 9 | import { asyncMiddleware } from '../middlewares' |
6 | import { AvatarModel } from '../models/avatar/avatar' | 10 | import { AvatarModel } from '../models/avatar/avatar' |
7 | import { logger } from '../helpers/logger' | ||
8 | import { avatarPathUnsafeCache, pushAvatarProcessInQueue } from '../lib/avatar' | ||
9 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | ||
10 | 11 | ||
11 | const lazyStaticRouter = express.Router() | 12 | const lazyStaticRouter = express.Router() |
12 | 13 | ||
@@ -27,6 +28,11 @@ lazyStaticRouter.use( | |||
27 | asyncMiddleware(getVideoCaption) | 28 | asyncMiddleware(getVideoCaption) |
28 | ) | 29 | ) |
29 | 30 | ||
31 | lazyStaticRouter.use( | ||
32 | LAZY_STATIC_PATHS.TORRENTS + ':filename', | ||
33 | asyncMiddleware(getTorrent) | ||
34 | ) | ||
35 | |||
30 | // --------------------------------------------------------------------------- | 36 | // --------------------------------------------------------------------------- |
31 | 37 | ||
32 | export { | 38 | export { |
@@ -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 | ||
73 | async function getPreview (req: express.Request, res: express.Response) { | 79 | async 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 | ||
80 | async function getVideoCaption (req: express.Request, res: express.Response) { | 86 | async 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 | |||
93 | async 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 | } |