diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-23 09:48:48 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | a8b666e9f1ed002230869606308749614390c82f (patch) | |
tree | 9fb59c3f322cf77ac6b37cc27e2c726f0e10c7ba /server/controllers | |
parent | 7663e55a2cc46a413bceee2787d48902b15ae642 (diff) | |
download | PeerTube-a8b666e9f1ed002230869606308749614390c82f.tar.gz PeerTube-a8b666e9f1ed002230869606308749614390c82f.tar.zst PeerTube-a8b666e9f1ed002230869606308749614390c82f.zip |
Add plugin static files cache
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/videos/blacklist.ts | 6 | ||||
-rw-r--r-- | server/controllers/plugins.ts | 19 |
2 files changed, 18 insertions, 7 deletions
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index 27dcfb761..0ec518e0d 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts | |||
@@ -100,13 +100,13 @@ async function updateVideoBlacklistController (req: express.Request, res: expres | |||
100 | return res.type('json').status(204).end() | 100 | return res.type('json').status(204).end() |
101 | } | 101 | } |
102 | 102 | ||
103 | async function listBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) { | 103 | async function listBlacklist (req: express.Request, res: express.Response) { |
104 | const resultList = await VideoBlacklistModel.listForApi(req.query.start, req.query.count, req.query.sort, req.query.type) | 104 | const resultList = await VideoBlacklistModel.listForApi(req.query.start, req.query.count, req.query.sort, req.query.type) |
105 | 105 | ||
106 | return res.json(getFormattedObjects<VideoBlacklist, VideoBlacklistModel>(resultList.data, resultList.total)) | 106 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
107 | } | 107 | } |
108 | 108 | ||
109 | async function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) { | 109 | async function removeVideoFromBlacklistController (req: express.Request, res: express.Response) { |
110 | const videoBlacklist = res.locals.videoBlacklist | 110 | const videoBlacklist = res.locals.videoBlacklist |
111 | const video = res.locals.video | 111 | const video = res.locals.video |
112 | 112 | ||
diff --git a/server/controllers/plugins.ts b/server/controllers/plugins.ts index f255d13e8..f5285ba3a 100644 --- a/server/controllers/plugins.ts +++ b/server/controllers/plugins.ts | |||
@@ -5,6 +5,12 @@ import { RegisteredPlugin } from '../lib/plugins/plugin-manager' | |||
5 | import { servePluginStaticDirectoryValidator } from '../middlewares/validators/plugins' | 5 | import { servePluginStaticDirectoryValidator } from '../middlewares/validators/plugins' |
6 | import { serveThemeCSSValidator } from '../middlewares/validators/themes' | 6 | import { serveThemeCSSValidator } from '../middlewares/validators/themes' |
7 | import { PluginType } from '../../shared/models/plugins/plugin.type' | 7 | import { PluginType } from '../../shared/models/plugins/plugin.type' |
8 | import { isTestInstance } from '../helpers/core-utils' | ||
9 | |||
10 | const sendFileOptions = { | ||
11 | maxAge: '30 days', | ||
12 | immutable: !isTestInstance() | ||
13 | } | ||
8 | 14 | ||
9 | const pluginsRouter = express.Router() | 15 | const pluginsRouter = express.Router() |
10 | 16 | ||
@@ -46,7 +52,12 @@ export { | |||
46 | // --------------------------------------------------------------------------- | 52 | // --------------------------------------------------------------------------- |
47 | 53 | ||
48 | function servePluginGlobalCSS (req: express.Request, res: express.Response) { | 54 | function servePluginGlobalCSS (req: express.Request, res: express.Response) { |
49 | return res.sendFile(PLUGIN_GLOBAL_CSS_PATH) | 55 | // Only cache requests that have a ?hash=... query param |
56 | const globalCSSOptions = req.query.hash | ||
57 | ? sendFileOptions | ||
58 | : {} | ||
59 | |||
60 | return res.sendFile(PLUGIN_GLOBAL_CSS_PATH, globalCSSOptions) | ||
50 | } | 61 | } |
51 | 62 | ||
52 | function servePluginStaticDirectory (req: express.Request, res: express.Response) { | 63 | function servePluginStaticDirectory (req: express.Request, res: express.Response) { |
@@ -61,7 +72,7 @@ function servePluginStaticDirectory (req: express.Request, res: express.Response | |||
61 | } | 72 | } |
62 | 73 | ||
63 | const filepath = file.join('/') | 74 | const filepath = file.join('/') |
64 | return res.sendFile(join(plugin.path, staticPath, filepath)) | 75 | return res.sendFile(join(plugin.path, staticPath, filepath), sendFileOptions) |
65 | } | 76 | } |
66 | 77 | ||
67 | function servePluginClientScripts (req: express.Request, res: express.Response) { | 78 | function servePluginClientScripts (req: express.Request, res: express.Response) { |
@@ -73,7 +84,7 @@ function servePluginClientScripts (req: express.Request, res: express.Response) | |||
73 | return res.sendStatus(404) | 84 | return res.sendStatus(404) |
74 | } | 85 | } |
75 | 86 | ||
76 | return res.sendFile(join(plugin.path, staticEndpoint)) | 87 | return res.sendFile(join(plugin.path, staticEndpoint), sendFileOptions) |
77 | } | 88 | } |
78 | 89 | ||
79 | function serveThemeCSSDirectory (req: express.Request, res: express.Response) { | 90 | function serveThemeCSSDirectory (req: express.Request, res: express.Response) { |
@@ -84,5 +95,5 @@ function serveThemeCSSDirectory (req: express.Request, res: express.Response) { | |||
84 | return res.sendStatus(404) | 95 | return res.sendStatus(404) |
85 | } | 96 | } |
86 | 97 | ||
87 | return res.sendFile(join(plugin.path, staticEndpoint)) | 98 | return res.sendFile(join(plugin.path, staticEndpoint), sendFileOptions) |
88 | } | 99 | } |