diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/plugins.ts | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/server/controllers/plugins.ts b/server/controllers/plugins.ts index a6705d9c7..05f03324d 100644 --- a/server/controllers/plugins.ts +++ b/server/controllers/plugins.ts | |||
@@ -1,21 +1,21 @@ | |||
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 { join } from 'path' | 3 | import { basename, 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 | 6 | ||
7 | const pluginsRouter = express.Router() | 7 | const pluginsRouter = express.Router() |
8 | 8 | ||
9 | pluginsRouter.get('/global.css', | 9 | pluginsRouter.get('/global.css', |
10 | express.static(PLUGIN_GLOBAL_CSS_PATH, { fallthrough: false }) | 10 | servePluginGlobalCSS |
11 | ) | 11 | ) |
12 | 12 | ||
13 | pluginsRouter.get('/:pluginName/:pluginVersion/statics/:staticEndpoint', | 13 | pluginsRouter.get('/:pluginName/:pluginVersion/static/:staticEndpoint(*)', |
14 | servePluginStaticDirectoryValidator, | 14 | servePluginStaticDirectoryValidator, |
15 | servePluginStaticDirectory | 15 | servePluginStaticDirectory |
16 | ) | 16 | ) |
17 | 17 | ||
18 | pluginsRouter.get('/:pluginName/:pluginVersion/client-scripts/:staticEndpoint', | 18 | pluginsRouter.get('/:pluginName/:pluginVersion/client-scripts/:staticEndpoint(*)', |
19 | servePluginStaticDirectoryValidator, | 19 | servePluginStaticDirectoryValidator, |
20 | servePluginClientScripts | 20 | servePluginClientScripts |
21 | ) | 21 | ) |
@@ -28,21 +28,33 @@ export { | |||
28 | 28 | ||
29 | // --------------------------------------------------------------------------- | 29 | // --------------------------------------------------------------------------- |
30 | 30 | ||
31 | function servePluginGlobalCSS (req: express.Request, res: express.Response) { | ||
32 | return res.sendFile(PLUGIN_GLOBAL_CSS_PATH) | ||
33 | } | ||
34 | |||
31 | function servePluginStaticDirectory (req: express.Request, res: express.Response) { | 35 | function servePluginStaticDirectory (req: express.Request, res: express.Response) { |
32 | const plugin: RegisteredPlugin = res.locals.registeredPlugin | 36 | const plugin: RegisteredPlugin = res.locals.registeredPlugin |
33 | const staticEndpoint = req.params.staticEndpoint | 37 | const staticEndpoint = req.params.staticEndpoint |
34 | 38 | ||
35 | const staticPath = plugin.staticDirs[staticEndpoint] | 39 | const [ directory, ...file ] = staticEndpoint.split('/') |
40 | |||
41 | const staticPath = plugin.staticDirs[directory] | ||
36 | if (!staticPath) { | 42 | if (!staticPath) { |
37 | return res.sendStatus(404) | 43 | return res.sendStatus(404) |
38 | } | 44 | } |
39 | 45 | ||
40 | return express.static(join(plugin.path, staticPath), { fallthrough: false }) | 46 | const filepath = file.join('/') |
47 | return res.sendFile(join(plugin.path, staticPath, filepath)) | ||
41 | } | 48 | } |
42 | 49 | ||
43 | function servePluginClientScripts (req: express.Request, res: express.Response) { | 50 | function servePluginClientScripts (req: express.Request, res: express.Response) { |
44 | const plugin: RegisteredPlugin = res.locals.registeredPlugin | 51 | const plugin: RegisteredPlugin = res.locals.registeredPlugin |
45 | const staticEndpoint = req.params.staticEndpoint | 52 | const staticEndpoint = req.params.staticEndpoint |
46 | 53 | ||
47 | return express.static(join(plugin.path, staticEndpoint), { fallthrough: false }) | 54 | const file = plugin.clientScripts[staticEndpoint] |
55 | if (!file) { | ||
56 | return res.sendStatus(404) | ||
57 | } | ||
58 | |||
59 | return res.sendFile(join(plugin.path, staticEndpoint)) | ||
48 | } | 60 | } |