From 20bafcb61bee2a9a10a500908850c9a7d5e3c8c5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 22 Jul 2021 11:15:17 +0200 Subject: Move apicache in peertube Allow us to upgrade to node 16 --- server/controllers/activitypub/client.ts | 4 ++-- server/controllers/api/server/stats.ts | 4 ++-- server/controllers/bots.ts | 4 ++-- server/controllers/feeds.ts | 24 ++++++++---------------- server/controllers/static.ts | 12 ++++++------ 5 files changed, 20 insertions(+), 28 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index d7de1b9bd..bef4bc068 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts @@ -24,7 +24,7 @@ import { videosCustomGetValidator, videosShareValidator } from '../../middlewares' -import { cacheRoute } from '../../middlewares/cache' +import { cacheRoute } from '../../middlewares/cache/cache' import { getAccountVideoRateValidatorFactory, videoCommentGetValidator } from '../../middlewares/validators' import { videoFileRedundancyGetValidator, videoPlaylistRedundancyGetValidator } from '../../middlewares/validators/redundancy' import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists' @@ -77,7 +77,7 @@ activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId', activityPubClientRouter.get( [ '/videos/watch/:id', '/w/:id' ], executeIfActivityPub, - asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS)), + cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS), asyncMiddleware(videosCustomGetValidator('all')), asyncMiddleware(videoController) ) diff --git a/server/controllers/api/server/stats.ts b/server/controllers/api/server/stats.ts index 3aea12450..397702548 100644 --- a/server/controllers/api/server/stats.ts +++ b/server/controllers/api/server/stats.ts @@ -2,12 +2,12 @@ import * as express from 'express' import { StatsManager } from '@server/lib/stat-manager' import { ROUTE_CACHE_LIFETIME } from '../../../initializers/constants' import { asyncMiddleware } from '../../../middlewares' -import { cacheRoute } from '../../../middlewares/cache' +import { cacheRoute } from '../../../middlewares/cache/cache' const statsRouter = express.Router() statsRouter.get('/stats', - asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.STATS)), + cacheRoute(ROUTE_CACHE_LIFETIME.STATS), asyncMiddleware(getStats) ) diff --git a/server/controllers/bots.ts b/server/controllers/bots.ts index 9e92063d4..93aa0cf30 100644 --- a/server/controllers/bots.ts +++ b/server/controllers/bots.ts @@ -5,7 +5,7 @@ import { SitemapStream, streamToPromise } from 'sitemap' import { VideoModel } from '../models/video/video' import { VideoChannelModel } from '../models/video/video-channel' import { AccountModel } from '../models/account/account' -import { cacheRoute } from '../middlewares/cache' +import { cacheRoute } from '../middlewares/cache/cache' import { buildNSFWFilter } from '../helpers/express-utils' import { truncate } from 'lodash' @@ -14,7 +14,7 @@ const botsRouter = express.Router() // Special route that add OpenGraph and oEmbed tags // Do not use a template engine for a so little thing botsRouter.use('/sitemap.xml', - asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.SITEMAP)), + cacheRoute(ROUTE_CACHE_LIFETIME.SITEMAP), asyncMiddleware(getSitemap) ) diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts index 435b12193..cdc6bfb8b 100644 --- a/server/controllers/feeds.ts +++ b/server/controllers/feeds.ts @@ -16,20 +16,20 @@ import { videosSortValidator, videoSubscriptionFeedsValidator } from '../middlewares' -import { cacheRoute } from '../middlewares/cache' +import { cacheRouteFactory } from '../middlewares/cache/cache' import { VideoModel } from '../models/video/video' import { VideoCommentModel } from '../models/video/video-comment' const feedsRouter = express.Router() +const cacheRoute = cacheRouteFactory({ + headerBlacklist: [ 'Content-Type' ] +}) + feedsRouter.get('/feeds/video-comments.:format', feedsFormatValidator, setFeedFormatContentType, - asyncMiddleware(cacheRoute({ - headerBlacklist: [ - 'Content-Type' - ] - })(ROUTE_CACHE_LIFETIME.FEEDS)), + cacheRoute(ROUTE_CACHE_LIFETIME.FEEDS), asyncMiddleware(videoFeedsValidator), asyncMiddleware(videoCommentsFeedsValidator), asyncMiddleware(generateVideoCommentsFeed) @@ -40,11 +40,7 @@ feedsRouter.get('/feeds/videos.:format', setDefaultVideosSort, feedsFormatValidator, setFeedFormatContentType, - asyncMiddleware(cacheRoute({ - headerBlacklist: [ - 'Content-Type' - ] - })(ROUTE_CACHE_LIFETIME.FEEDS)), + cacheRoute(ROUTE_CACHE_LIFETIME.FEEDS), commonVideosFiltersValidator, asyncMiddleware(videoFeedsValidator), asyncMiddleware(generateVideoFeed) @@ -55,11 +51,7 @@ feedsRouter.get('/feeds/subscriptions.:format', setDefaultVideosSort, feedsFormatValidator, setFeedFormatContentType, - asyncMiddleware(cacheRoute({ - headerBlacklist: [ - 'Content-Type' - ] - })(ROUTE_CACHE_LIFETIME.FEEDS)), + cacheRoute(ROUTE_CACHE_LIFETIME.FEEDS), commonVideosFiltersValidator, asyncMiddleware(videoSubscriptionFeedsValidator), asyncMiddleware(generateVideoFeedForSubscriptions) diff --git a/server/controllers/static.ts b/server/controllers/static.ts index 5900eaff3..912d7e36c 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts @@ -19,7 +19,7 @@ import { } from '../initializers/constants' import { getThemeOrDefault } from '../lib/plugins/theme-utils' import { asyncMiddleware } from '../middlewares' -import { cacheRoute } from '../middlewares/cache' +import { cacheRoute } from '../middlewares/cache/cache' import { UserModel } from '../models/user/user' import { VideoModel } from '../models/video/video' import { VideoCommentModel } from '../models/video/video-comment' @@ -66,7 +66,7 @@ staticRouter.use( // robots.txt service staticRouter.get('/robots.txt', - asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.ROBOTS)), + cacheRoute(ROUTE_CACHE_LIFETIME.ROBOTS), (_, res: express.Response) => { res.type('text/plain') return res.send(CONFIG.INSTANCE.ROBOTS) @@ -86,7 +86,7 @@ staticRouter.get('/security.txt', ) staticRouter.get('/.well-known/security.txt', - asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.SECURITYTXT)), + cacheRoute(ROUTE_CACHE_LIFETIME.SECURITYTXT), (_, res: express.Response) => { res.type('text/plain') return res.send(CONFIG.INSTANCE.SECURITYTXT + CONFIG.INSTANCE.SECURITYTXT_CONTACT) @@ -95,7 +95,7 @@ staticRouter.get('/.well-known/security.txt', // nodeinfo service staticRouter.use('/.well-known/nodeinfo', - asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.NODEINFO)), + cacheRoute(ROUTE_CACHE_LIFETIME.NODEINFO), (_, res: express.Response) => { return res.json({ links: [ @@ -108,13 +108,13 @@ staticRouter.use('/.well-known/nodeinfo', } ) staticRouter.use('/nodeinfo/:version.json', - asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.NODEINFO)), + cacheRoute(ROUTE_CACHE_LIFETIME.NODEINFO), asyncMiddleware(generateNodeinfo) ) // dnt-policy.txt service (see https://www.eff.org/dnt-policy) staticRouter.use('/.well-known/dnt-policy.txt', - asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.DNT_POLICY)), + cacheRoute(ROUTE_CACHE_LIFETIME.DNT_POLICY), (_, res: express.Response) => { res.type('text/plain') -- cgit v1.2.3