diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-26 09:35:43 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-07-26 15:18:29 +0200 |
commit | ba211e7386bb2f25e37a4c5bcdfeb4237e1cd315 (patch) | |
tree | 398bb14a92c7df3765a0a64bac9f4672c5588488 /server/controllers/api/plugins.ts | |
parent | 23bdacf8ec24ce47a15529830e116911d7478598 (diff) | |
download | PeerTube-ba211e7386bb2f25e37a4c5bcdfeb4237e1cd315.tar.gz PeerTube-ba211e7386bb2f25e37a4c5bcdfeb4237e1cd315.tar.zst PeerTube-ba211e7386bb2f25e37a4c5bcdfeb4237e1cd315.zip |
Add public settings endpoint
Diffstat (limited to 'server/controllers/api/plugins.ts')
-rw-r--r-- | server/controllers/api/plugins.ts | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/server/controllers/api/plugins.ts b/server/controllers/api/plugins.ts index 86384ee27..6b7562fd3 100644 --- a/server/controllers/api/plugins.ts +++ b/server/controllers/api/plugins.ts | |||
@@ -26,6 +26,7 @@ import { logger } from '../../helpers/logger' | |||
26 | import { listAvailablePluginsFromIndex } from '../../lib/plugins/plugin-index' | 26 | import { listAvailablePluginsFromIndex } from '../../lib/plugins/plugin-index' |
27 | import { PeertubePluginIndexList } from '../../../shared/models/plugins/peertube-plugin-index-list.model' | 27 | import { PeertubePluginIndexList } from '../../../shared/models/plugins/peertube-plugin-index-list.model' |
28 | import { RegisteredServerSettings } from '../../../shared/models/plugins/register-server-setting.model' | 28 | import { RegisteredServerSettings } from '../../../shared/models/plugins/register-server-setting.model' |
29 | import { PublicServerSetting } from '../../../shared/models/plugins/public-server.setting' | ||
29 | 30 | ||
30 | const pluginRouter = express.Router() | 31 | const pluginRouter = express.Router() |
31 | 32 | ||
@@ -51,18 +52,16 @@ pluginRouter.get('/', | |||
51 | asyncMiddleware(listPlugins) | 52 | asyncMiddleware(listPlugins) |
52 | ) | 53 | ) |
53 | 54 | ||
54 | pluginRouter.get('/:npmName', | 55 | pluginRouter.get('/:npmName/registered-settings', |
55 | authenticate, | 56 | authenticate, |
56 | ensureUserHasRight(UserRight.MANAGE_PLUGINS), | 57 | ensureUserHasRight(UserRight.MANAGE_PLUGINS), |
57 | asyncMiddleware(existingPluginValidator), | 58 | asyncMiddleware(existingPluginValidator), |
58 | getPlugin | 59 | getPluginRegisteredSettings |
59 | ) | 60 | ) |
60 | 61 | ||
61 | pluginRouter.get('/:npmName/registered-settings', | 62 | pluginRouter.get('/:npmName/public-settings', |
62 | authenticate, | ||
63 | ensureUserHasRight(UserRight.MANAGE_PLUGINS), | ||
64 | asyncMiddleware(existingPluginValidator), | 63 | asyncMiddleware(existingPluginValidator), |
65 | getPluginRegisteredSettings | 64 | getPublicPluginSettings |
66 | ) | 65 | ) |
67 | 66 | ||
68 | pluginRouter.put('/:npmName/settings', | 67 | pluginRouter.put('/:npmName/settings', |
@@ -73,6 +72,13 @@ pluginRouter.put('/:npmName/settings', | |||
73 | asyncMiddleware(updatePluginSettings) | 72 | asyncMiddleware(updatePluginSettings) |
74 | ) | 73 | ) |
75 | 74 | ||
75 | pluginRouter.get('/:npmName', | ||
76 | authenticate, | ||
77 | ensureUserHasRight(UserRight.MANAGE_PLUGINS), | ||
78 | asyncMiddleware(existingPluginValidator), | ||
79 | getPlugin | ||
80 | ) | ||
81 | |||
76 | pluginRouter.post('/install', | 82 | pluginRouter.post('/install', |
77 | authenticate, | 83 | authenticate, |
78 | ensureUserHasRight(UserRight.MANAGE_PLUGINS), | 84 | ensureUserHasRight(UserRight.MANAGE_PLUGINS), |
@@ -161,10 +167,20 @@ async function uninstallPlugin (req: express.Request, res: express.Response) { | |||
161 | return res.sendStatus(204) | 167 | return res.sendStatus(204) |
162 | } | 168 | } |
163 | 169 | ||
170 | function getPublicPluginSettings (req: express.Request, res: express.Response) { | ||
171 | const plugin = res.locals.plugin | ||
172 | const registeredSettings = PluginManager.Instance.getRegisteredSettings(req.params.npmName) | ||
173 | const publicSettings = plugin.getPublicSettings(registeredSettings) | ||
174 | |||
175 | const json: PublicServerSetting = { publicSettings } | ||
176 | |||
177 | return res.json(json) | ||
178 | } | ||
179 | |||
164 | function getPluginRegisteredSettings (req: express.Request, res: express.Response) { | 180 | function getPluginRegisteredSettings (req: express.Request, res: express.Response) { |
165 | const settings = PluginManager.Instance.getRegisteredSettings(req.params.npmName) | 181 | const registeredSettings = PluginManager.Instance.getRegisteredSettings(req.params.npmName) |
166 | 182 | ||
167 | const json: RegisteredServerSettings = { settings } | 183 | const json: RegisteredServerSettings = { registeredSettings } |
168 | 184 | ||
169 | return res.json(json) | 185 | return res.json(json) |
170 | } | 186 | } |