aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/plugins.ts16
-rw-r--r--server/controllers/themes.ts30
2 files changed, 12 insertions, 34 deletions
diff --git a/server/controllers/api/plugins.ts b/server/controllers/api/plugins.ts
index f17e8cab9..8e59f27cf 100644
--- a/server/controllers/api/plugins.ts
+++ b/server/controllers/api/plugins.ts
@@ -21,6 +21,7 @@ import {
21import { PluginManager } from '../../lib/plugins/plugin-manager' 21import { PluginManager } from '../../lib/plugins/plugin-manager'
22import { InstallPlugin } from '../../../shared/models/plugins/install-plugin.model' 22import { InstallPlugin } from '../../../shared/models/plugins/install-plugin.model'
23import { ManagePlugin } from '../../../shared/models/plugins/manage-plugin.model' 23import { ManagePlugin } from '../../../shared/models/plugins/manage-plugin.model'
24import { logger } from '../../helpers/logger'
24 25
25const pluginRouter = express.Router() 26const pluginRouter = express.Router()
26 27
@@ -46,7 +47,7 @@ pluginRouter.get('/:npmName/registered-settings',
46 authenticate, 47 authenticate,
47 ensureUserHasRight(UserRight.MANAGE_PLUGINS), 48 ensureUserHasRight(UserRight.MANAGE_PLUGINS),
48 asyncMiddleware(existingPluginValidator), 49 asyncMiddleware(existingPluginValidator),
49 asyncMiddleware(getPluginRegisteredSettings) 50 getPluginRegisteredSettings
50) 51)
51 52
52pluginRouter.put('/:npmName/settings', 53pluginRouter.put('/:npmName/settings',
@@ -101,7 +102,14 @@ function getPlugin (req: express.Request, res: express.Response) {
101async function installPlugin (req: express.Request, res: express.Response) { 102async function installPlugin (req: express.Request, res: express.Response) {
102 const body: InstallPlugin = req.body 103 const body: InstallPlugin = req.body
103 104
104 await PluginManager.Instance.install(body.npmName) 105 const fromDisk = !!body.path
106 const toInstall = body.npmName || body.path
107 try {
108 await PluginManager.Instance.install(toInstall, undefined, fromDisk)
109 } catch (err) {
110 logger.warn('Cannot install plugin %s.', toInstall, { err })
111 return res.sendStatus(400)
112 }
105 113
106 return res.sendStatus(204) 114 return res.sendStatus(204)
107} 115}
@@ -114,10 +122,10 @@ async function uninstallPlugin (req: express.Request, res: express.Response) {
114 return res.sendStatus(204) 122 return res.sendStatus(204)
115} 123}
116 124
117async function getPluginRegisteredSettings (req: express.Request, res: express.Response) { 125function getPluginRegisteredSettings (req: express.Request, res: express.Response) {
118 const plugin = res.locals.plugin 126 const plugin = res.locals.plugin
119 127
120 const settings = await PluginManager.Instance.getSettings(plugin.name) 128 const settings = PluginManager.Instance.getSettings(plugin.name)
121 129
122 return res.json({ 130 return res.json({
123 settings 131 settings
diff --git a/server/controllers/themes.ts b/server/controllers/themes.ts
deleted file mode 100644
index 104c285ad..000000000
--- a/server/controllers/themes.ts
+++ /dev/null
@@ -1,30 +0,0 @@
1import * as express from 'express'
2import { join } from 'path'
3import { RegisteredPlugin } from '../lib/plugins/plugin-manager'
4import { serveThemeCSSValidator } from '../middlewares/validators/themes'
5
6const themesRouter = express.Router()
7
8themesRouter.get('/:themeName/:themeVersion/css/:staticEndpoint(*)',
9 serveThemeCSSValidator,
10 serveThemeCSSDirectory
11)
12
13// ---------------------------------------------------------------------------
14
15export {
16 themesRouter
17}
18
19// ---------------------------------------------------------------------------
20
21function serveThemeCSSDirectory (req: express.Request, res: express.Response) {
22 const plugin: RegisteredPlugin = res.locals.registeredPlugin
23 const staticEndpoint = req.params.staticEndpoint
24
25 if (plugin.css.includes(staticEndpoint) === false) {
26 return res.sendStatus(404)
27 }
28
29 return res.sendFile(join(plugin.path, staticEndpoint))
30}