diff options
Diffstat (limited to 'server/controllers/plugins.ts')
-rw-r--r-- | server/controllers/plugins.ts | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/server/controllers/plugins.ts b/server/controllers/plugins.ts index 05f03324d..f255d13e8 100644 --- a/server/controllers/plugins.ts +++ b/server/controllers/plugins.ts | |||
@@ -1,25 +1,42 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { PLUGIN_GLOBAL_CSS_PATH } from '../initializers/constants' | 2 | import { PLUGIN_GLOBAL_CSS_PATH } from '../initializers/constants' |
3 | import { basename, join } from 'path' | 3 | import { join } from 'path' |
4 | import { RegisteredPlugin } from '../lib/plugins/plugin-manager' | 4 | 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' | ||
7 | import { PluginType } from '../../shared/models/plugins/plugin.type' | ||
6 | 8 | ||
7 | const pluginsRouter = express.Router() | 9 | const pluginsRouter = express.Router() |
8 | 10 | ||
9 | pluginsRouter.get('/global.css', | 11 | pluginsRouter.get('/plugins/global.css', |
10 | servePluginGlobalCSS | 12 | servePluginGlobalCSS |
11 | ) | 13 | ) |
12 | 14 | ||
13 | pluginsRouter.get('/:pluginName/:pluginVersion/static/:staticEndpoint(*)', | 15 | pluginsRouter.get('/plugins/:pluginName/:pluginVersion/static/:staticEndpoint(*)', |
14 | servePluginStaticDirectoryValidator, | 16 | servePluginStaticDirectoryValidator(PluginType.PLUGIN), |
15 | servePluginStaticDirectory | 17 | servePluginStaticDirectory |
16 | ) | 18 | ) |
17 | 19 | ||
18 | pluginsRouter.get('/:pluginName/:pluginVersion/client-scripts/:staticEndpoint(*)', | 20 | pluginsRouter.get('/plugins/:pluginName/:pluginVersion/client-scripts/:staticEndpoint(*)', |
19 | servePluginStaticDirectoryValidator, | 21 | servePluginStaticDirectoryValidator(PluginType.PLUGIN), |
20 | servePluginClientScripts | 22 | servePluginClientScripts |
21 | ) | 23 | ) |
22 | 24 | ||
25 | pluginsRouter.get('/themes/:pluginName/:pluginVersion/static/:staticEndpoint(*)', | ||
26 | servePluginStaticDirectoryValidator(PluginType.THEME), | ||
27 | servePluginStaticDirectory | ||
28 | ) | ||
29 | |||
30 | pluginsRouter.get('/themes/:pluginName/:pluginVersion/client-scripts/:staticEndpoint(*)', | ||
31 | servePluginStaticDirectoryValidator(PluginType.THEME), | ||
32 | servePluginClientScripts | ||
33 | ) | ||
34 | |||
35 | pluginsRouter.get('/themes/:themeName/:themeVersion/css/:staticEndpoint(*)', | ||
36 | serveThemeCSSValidator, | ||
37 | serveThemeCSSDirectory | ||
38 | ) | ||
39 | |||
23 | // --------------------------------------------------------------------------- | 40 | // --------------------------------------------------------------------------- |
24 | 41 | ||
25 | export { | 42 | export { |
@@ -58,3 +75,14 @@ function servePluginClientScripts (req: express.Request, res: express.Response) | |||
58 | 75 | ||
59 | return res.sendFile(join(plugin.path, staticEndpoint)) | 76 | return res.sendFile(join(plugin.path, staticEndpoint)) |
60 | } | 77 | } |
78 | |||
79 | function serveThemeCSSDirectory (req: express.Request, res: express.Response) { | ||
80 | const plugin: RegisteredPlugin = res.locals.registeredPlugin | ||
81 | const staticEndpoint = req.params.staticEndpoint | ||
82 | |||
83 | if (plugin.css.includes(staticEndpoint) === false) { | ||
84 | return res.sendStatus(404) | ||
85 | } | ||
86 | |||
87 | return res.sendFile(join(plugin.path, staticEndpoint)) | ||
88 | } | ||