From a8b1b40485145ac1eae513a661d7dd6e0986ce96 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 12 Feb 2021 16:23:19 +0100 Subject: Generate a name for thumbnails Allows aggressive caching --- server/controllers/lazy-static.ts | 4 ++-- server/controllers/static.ts | 29 ++++++++++++++--------------- 2 files changed, 16 insertions(+), 17 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/lazy-static.ts b/server/controllers/lazy-static.ts index 5c6369c9e..847d24fd4 100644 --- a/server/controllers/lazy-static.ts +++ b/server/controllers/lazy-static.ts @@ -18,7 +18,7 @@ lazyStaticRouter.use( ) lazyStaticRouter.use( - LAZY_STATIC_PATHS.PREVIEWS + ':uuid.jpg', + LAZY_STATIC_PATHS.PREVIEWS + ':filename', asyncMiddleware(getPreview) ) @@ -71,7 +71,7 @@ async function getAvatar (req: express.Request, res: express.Response) { } async function getPreview (req: express.Request, res: express.Response) { - const result = await VideosPreviewCache.Instance.getFilePath(req.params.uuid) + 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 }) diff --git a/server/controllers/static.ts b/server/controllers/static.ts index a645c496b..2064857eb 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts @@ -1,5 +1,15 @@ import * as cors from 'cors' import * as express from 'express' +import { join } from 'path' +import { getRegisteredPlugins, getRegisteredThemes } from '@server/controllers/api/config' +import { serveIndexHTML } from '@server/lib/client-html' +import { getTorrentFilePath, getVideoFilePath } from '@server/lib/video-paths' +import { MVideoFile, MVideoFullLight } from '@server/types/models' +import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' +import { VideoStreamingPlaylistType } from '@shared/models/videos/video-streaming-playlist.type' +import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo' +import { root } from '../helpers/core-utils' +import { CONFIG, isEmailEnabled } from '../initializers/config' import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, @@ -11,24 +21,13 @@ import { STATIC_PATHS, WEBSERVER } from '../initializers/constants' -import { cacheRoute } from '../middlewares/cache' +import { getThemeOrDefault } from '../lib/plugins/theme-utils' +import { getEnabledResolutions } from '../lib/video-transcoding' import { asyncMiddleware, videosDownloadValidator } from '../middlewares' -import { VideoModel } from '../models/video/video' +import { cacheRoute } from '../middlewares/cache' import { UserModel } from '../models/account/user' +import { VideoModel } from '../models/video/video' import { VideoCommentModel } from '../models/video/video-comment' -import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo' -import { join } from 'path' -import { root } from '../helpers/core-utils' -import { getEnabledResolutions } from '../lib/video-transcoding' -import { CONFIG, isEmailEnabled } from '../initializers/config' -import { getPreview, getVideoCaption } from './lazy-static' -import { VideoStreamingPlaylistType } from '@shared/models/videos/video-streaming-playlist.type' -import { MVideoFile, MVideoFullLight } from '@server/types/models' -import { getTorrentFilePath, getVideoFilePath } from '@server/lib/video-paths' -import { getThemeOrDefault } from '../lib/plugins/theme-utils' -import { getRegisteredPlugins, getRegisteredThemes } from '@server/controllers/api/config' -import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' -import { serveIndexHTML } from '@server/lib/client-html' const staticRouter = express.Router() -- cgit v1.2.3