aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/plugins.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/plugins.ts')
-rw-r--r--server/controllers/plugins.ts20
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { PLUGIN_GLOBAL_CSS_PATH } from '../initializers/constants' 2import { PLUGIN_GLOBAL_CSS_PATH } from '../initializers/constants'
3import { join } from 'path' 3import { join } from 'path'
4import { RegisteredPlugin } from '../lib/plugins/plugin-manager' 4import { PluginManager, RegisteredPlugin } from '../lib/plugins/plugin-manager'
5import { servePluginStaticDirectoryValidator } from '../middlewares/validators/plugins' 5import { servePluginStaticDirectoryValidator } from '../middlewares/validators/plugins'
6import { serveThemeCSSValidator } from '../middlewares/validators/themes' 6import { serveThemeCSSValidator } from '../middlewares/validators/themes'
7import { PluginType } from '../../shared/models/plugins/plugin.type' 7import { PluginType } from '../../shared/models/plugins/plugin.type'
8import { isTestInstance } from '../helpers/core-utils' 8import { isTestInstance } from '../helpers/core-utils'
9import { getCompleteLocale, is18nLocale } from '../../shared/models/i18n'
9 10
10const sendFileOptions = { 11const 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
22pluginsRouter.get('/plugins/translations/:locale.json',
23 getPluginTranslations
24)
25
21pluginsRouter.get('/plugins/:pluginName/:pluginVersion/static/:staticEndpoint(*)', 26pluginsRouter.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
68function 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
63function servePluginStaticDirectory (req: express.Request, res: express.Response) { 81function 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