diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-11 14:40:19 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8 (patch) | |
tree | 7695023d90b78f972abafc718346c50264587ff5 /server/controllers/api/plugins.ts | |
parent | d00dc28dd73ad9dd419d5a5ac6ac747cefbc6e8b (diff) | |
download | PeerTube-dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8.tar.gz PeerTube-dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8.tar.zst PeerTube-dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8.zip |
WIP plugins: add plugin settings/uninstall in client
Diffstat (limited to 'server/controllers/api/plugins.ts')
-rw-r--r-- | server/controllers/api/plugins.ts | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/server/controllers/api/plugins.ts b/server/controllers/api/plugins.ts index 89cc67f54..f17e8cab9 100644 --- a/server/controllers/api/plugins.ts +++ b/server/controllers/api/plugins.ts | |||
@@ -12,7 +12,7 @@ import { pluginsSortValidator } from '../../middlewares/validators' | |||
12 | import { PluginModel } from '../../models/server/plugin' | 12 | import { PluginModel } from '../../models/server/plugin' |
13 | import { UserRight } from '../../../shared/models/users' | 13 | import { UserRight } from '../../../shared/models/users' |
14 | import { | 14 | import { |
15 | enabledPluginValidator, | 15 | existingPluginValidator, |
16 | installPluginValidator, | 16 | installPluginValidator, |
17 | listPluginsValidator, | 17 | listPluginsValidator, |
18 | uninstallPluginValidator, | 18 | uninstallPluginValidator, |
@@ -35,18 +35,25 @@ pluginRouter.get('/', | |||
35 | asyncMiddleware(listPlugins) | 35 | asyncMiddleware(listPlugins) |
36 | ) | 36 | ) |
37 | 37 | ||
38 | pluginRouter.get('/:pluginName/settings', | 38 | pluginRouter.get('/:npmName', |
39 | authenticate, | 39 | authenticate, |
40 | ensureUserHasRight(UserRight.MANAGE_PLUGINS), | 40 | ensureUserHasRight(UserRight.MANAGE_PLUGINS), |
41 | asyncMiddleware(enabledPluginValidator), | 41 | asyncMiddleware(existingPluginValidator), |
42 | asyncMiddleware(listPluginSettings) | 42 | getPlugin |
43 | ) | 43 | ) |
44 | 44 | ||
45 | pluginRouter.put('/:pluginName/settings', | 45 | pluginRouter.get('/:npmName/registered-settings', |
46 | authenticate, | ||
47 | ensureUserHasRight(UserRight.MANAGE_PLUGINS), | ||
48 | asyncMiddleware(existingPluginValidator), | ||
49 | asyncMiddleware(getPluginRegisteredSettings) | ||
50 | ) | ||
51 | |||
52 | pluginRouter.put('/:npmName/settings', | ||
46 | authenticate, | 53 | authenticate, |
47 | ensureUserHasRight(UserRight.MANAGE_PLUGINS), | 54 | ensureUserHasRight(UserRight.MANAGE_PLUGINS), |
48 | updatePluginSettingsValidator, | 55 | updatePluginSettingsValidator, |
49 | asyncMiddleware(enabledPluginValidator), | 56 | asyncMiddleware(existingPluginValidator), |
50 | asyncMiddleware(updatePluginSettings) | 57 | asyncMiddleware(updatePluginSettings) |
51 | ) | 58 | ) |
52 | 59 | ||
@@ -85,6 +92,12 @@ async function listPlugins (req: express.Request, res: express.Response) { | |||
85 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 92 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
86 | } | 93 | } |
87 | 94 | ||
95 | function getPlugin (req: express.Request, res: express.Response) { | ||
96 | const plugin = res.locals.plugin | ||
97 | |||
98 | return res.json(plugin.toFormattedJSON()) | ||
99 | } | ||
100 | |||
88 | async function installPlugin (req: express.Request, res: express.Response) { | 101 | async function installPlugin (req: express.Request, res: express.Response) { |
89 | const body: InstallPlugin = req.body | 102 | const body: InstallPlugin = req.body |
90 | 103 | ||
@@ -101,7 +114,7 @@ async function uninstallPlugin (req: express.Request, res: express.Response) { | |||
101 | return res.sendStatus(204) | 114 | return res.sendStatus(204) |
102 | } | 115 | } |
103 | 116 | ||
104 | async function listPluginSettings (req: express.Request, res: express.Response) { | 117 | async function getPluginRegisteredSettings (req: express.Request, res: express.Response) { |
105 | const plugin = res.locals.plugin | 118 | const plugin = res.locals.plugin |
106 | 119 | ||
107 | const settings = await PluginManager.Instance.getSettings(plugin.name) | 120 | const settings = await PluginManager.Instance.getSettings(plugin.name) |