From 90a8bd305de4153ec21137a73ff482dcc2e3e19b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 16 Feb 2021 16:25:53 +0100 Subject: Dissociate video file names and video uuid --- server/controllers/lazy-static.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'server/controllers/lazy-static.ts') 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 @@ import * as cors from 'cors' import * as express from 'express' +import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache' +import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' +import { logger } from '../helpers/logger' import { LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants' +import { avatarPathUnsafeCache, pushAvatarProcessInQueue } from '../lib/avatar' import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache' import { asyncMiddleware } from '../middlewares' import { AvatarModel } from '../models/avatar/avatar' -import { logger } from '../helpers/logger' -import { avatarPathUnsafeCache, pushAvatarProcessInQueue } from '../lib/avatar' -import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' const lazyStaticRouter = express.Router() @@ -27,6 +28,11 @@ lazyStaticRouter.use( asyncMiddleware(getVideoCaption) ) +lazyStaticRouter.use( + LAZY_STATIC_PATHS.TORRENTS + ':filename', + asyncMiddleware(getTorrent) +) + // --------------------------------------------------------------------------- export { @@ -67,19 +73,26 @@ async function getAvatar (req: express.Request, res: express.Response) { const path = avatar.getPath() avatarPathUnsafeCache.set(filename, path) - return res.sendFile(path, { maxAge: STATIC_MAX_AGE.SERVER }) + return res.sendFile(path, { maxAge: STATIC_MAX_AGE.LAZY_SERVER }) } async function getPreview (req: express.Request, res: express.Response) { const result = await VideosPreviewCache.Instance.getFilePath(req.params.filename) if (!result) return res.sendStatus(HttpStatusCode.NOT_FOUND_404) - return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.SERVER }) + return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.LAZY_SERVER }) } async function getVideoCaption (req: express.Request, res: express.Response) { const result = await VideosCaptionCache.Instance.getFilePath(req.params.filename) if (!result) return res.sendStatus(HttpStatusCode.NOT_FOUND_404) + return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.LAZY_SERVER }) +} + +async function getTorrent (req: express.Request, res: express.Response) { + const result = await VideosTorrentCache.Instance.getFilePath(req.params.filename) + if (!result) return res.sendStatus(HttpStatusCode.NOT_FOUND_404) + return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.SERVER }) } -- cgit v1.2.3