diff options
Diffstat (limited to 'server/controllers/plugins.ts')
-rw-r--r-- | server/controllers/plugins.ts | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/server/controllers/plugins.ts b/server/controllers/plugins.ts index f5285ba3a..1caee9a29 100644 --- a/server/controllers/plugins.ts +++ b/server/controllers/plugins.ts | |||
@@ -1,11 +1,12 @@ | |||
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 { join } from 'path' |
4 | import { RegisteredPlugin } from '../lib/plugins/plugin-manager' | 4 | import { PluginManager, 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' | 8 | import { isTestInstance } from '../helpers/core-utils' |
9 | import { getCompleteLocale, is18nLocale } from '../../shared/models/i18n' | ||
9 | 10 | ||
10 | const sendFileOptions = { | 11 | const sendFileOptions = { |
11 | maxAge: '30 days', | 12 | maxAge: '30 days', |
@@ -18,6 +19,10 @@ pluginsRouter.get('/plugins/global.css', | |||
18 | servePluginGlobalCSS | 19 | servePluginGlobalCSS |
19 | ) | 20 | ) |
20 | 21 | ||
22 | pluginsRouter.get('/plugins/translations/:locale.json', | ||
23 | getPluginTranslations | ||
24 | ) | ||
25 | |||
21 | pluginsRouter.get('/plugins/:pluginName/:pluginVersion/static/:staticEndpoint(*)', | 26 | pluginsRouter.get('/plugins/:pluginName/:pluginVersion/static/:staticEndpoint(*)', |
22 | servePluginStaticDirectoryValidator(PluginType.PLUGIN), | 27 | servePluginStaticDirectoryValidator(PluginType.PLUGIN), |
23 | servePluginStaticDirectory | 28 | servePluginStaticDirectory |
@@ -60,6 +65,19 @@ function servePluginGlobalCSS (req: express.Request, res: express.Response) { | |||
60 | return res.sendFile(PLUGIN_GLOBAL_CSS_PATH, globalCSSOptions) | 65 | return res.sendFile(PLUGIN_GLOBAL_CSS_PATH, globalCSSOptions) |
61 | } | 66 | } |
62 | 67 | ||
68 | function getPluginTranslations (req: express.Request, res: express.Response) { | ||
69 | const locale = req.params.locale | ||
70 | |||
71 | if (is18nLocale(locale)) { | ||
72 | const completeLocale = getCompleteLocale(locale) | ||
73 | const json = PluginManager.Instance.getTranslations(completeLocale) | ||
74 | |||
75 | return res.json(json) | ||
76 | } | ||
77 | |||
78 | return res.sendStatus(404) | ||
79 | } | ||
80 | |||
63 | function servePluginStaticDirectory (req: express.Request, res: express.Response) { | 81 | function servePluginStaticDirectory (req: express.Request, res: express.Response) { |
64 | const plugin: RegisteredPlugin = res.locals.registeredPlugin | 82 | const plugin: RegisteredPlugin = res.locals.registeredPlugin |
65 | const staticEndpoint = req.params.staticEndpoint | 83 | const staticEndpoint = req.params.staticEndpoint |