From 557b13ae24019d9ab214bbea7eaa0f892c8f4b05 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Aug 2019 11:32:40 +0200 Subject: Lazy load avatars --- server/controllers/static.ts | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) (limited to 'server/controllers/static.ts') diff --git a/server/controllers/static.ts b/server/controllers/static.ts index 110d25031..8979ef5f3 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts @@ -9,7 +9,6 @@ import { STATIC_PATHS, WEBSERVER } from '../initializers/constants' -import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache' import { cacheRoute } from '../middlewares/cache' import { asyncMiddleware, videosGetValidator } from '../middlewares' import { VideoModel } from '../models/video/video' @@ -19,6 +18,7 @@ import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/node import { join } from 'path' import { root } from '../helpers/core-utils' import { CONFIG } from '../initializers/config' +import { getPreview, getVideoCaption } from './lazy-static' const staticRouter = express.Router() @@ -72,19 +72,20 @@ staticRouter.use( express.static(thumbnailsPhysicalPath, { maxAge: STATIC_MAX_AGE.SERVER, fallthrough: false }) // 404 if the file does not exist ) +// DEPRECATED: use lazy-static route instead const avatarsPhysicalPath = CONFIG.STORAGE.AVATARS_DIR staticRouter.use( STATIC_PATHS.AVATARS, express.static(avatarsPhysicalPath, { maxAge: STATIC_MAX_AGE.SERVER, fallthrough: false }) // 404 if the file does not exist ) -// We don't have video previews, fetch them from the origin instance +// DEPRECATED: use lazy-static route instead staticRouter.use( STATIC_PATHS.PREVIEWS + ':uuid.jpg', asyncMiddleware(getPreview) ) -// We don't have video captions, fetch them from the origin instance +// DEPRECATED: use lazy-static route instead staticRouter.use( STATIC_PATHS.VIDEO_CAPTIONS + ':videoId-:captionLanguage([a-z]+).vtt', asyncMiddleware(getVideoCaption) @@ -177,23 +178,6 @@ export { // --------------------------------------------------------------------------- -async function getPreview (req: express.Request, res: express.Response) { - const result = await VideosPreviewCache.Instance.getFilePath(req.params.uuid) - if (!result) return res.sendStatus(404) - - return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE }) -} - -async function getVideoCaption (req: express.Request, res: express.Response) { - const result = await VideosCaptionCache.Instance.getFilePath({ - videoId: req.params.videoId, - language: req.params.captionLanguage - }) - if (!result) return res.sendStatus(404) - - return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE }) -} - async function generateNodeinfo (req: express.Request, res: express.Response) { const { totalVideos } = await VideoModel.getStats() const { totalLocalVideoComments } = await VideoCommentModel.getStats() -- cgit v1.2.3