aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/plugins.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/plugins.ts')
-rw-r--r--server/middlewares/validators/plugins.ts23
1 files changed, 12 insertions, 11 deletions
diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.ts
index cba261dc0..bbac55a50 100644
--- a/server/middlewares/validators/plugins.ts
+++ b/server/middlewares/validators/plugins.ts
@@ -9,6 +9,7 @@ import { PluginModel } from '../../models/server/plugin'
9import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model' 9import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model'
10import { PluginType } from '../../../shared/models/plugins/plugin.type' 10import { PluginType } from '../../../shared/models/plugins/plugin.type'
11import { CONFIG } from '../../initializers/config' 11import { CONFIG } from '../../initializers/config'
12import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
12 13
13const getPluginValidator = (pluginType: PluginType, withVersion = true) => { 14const getPluginValidator = (pluginType: PluginType, withVersion = true) => {
14 const validators: (ValidationChain | express.Handler)[] = [ 15 const validators: (ValidationChain | express.Handler)[] = [
@@ -30,8 +31,8 @@ const getPluginValidator = (pluginType: PluginType, withVersion = true) => {
30 const npmName = PluginModel.buildNpmName(req.params.pluginName, pluginType) 31 const npmName = PluginModel.buildNpmName(req.params.pluginName, pluginType)
31 const plugin = PluginManager.Instance.getRegisteredPluginOrTheme(npmName) 32 const plugin = PluginManager.Instance.getRegisteredPluginOrTheme(npmName)
32 33
33 if (!plugin) return res.sendStatus(404) 34 if (!plugin) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
34 if (withVersion && plugin.version !== req.params.pluginVersion) return res.sendStatus(404) 35 if (withVersion && plugin.version !== req.params.pluginVersion) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
35 36
36 res.locals.registeredPlugin = plugin 37 res.locals.registeredPlugin = plugin
37 38
@@ -49,10 +50,10 @@ const getExternalAuthValidator = [
49 if (areValidationErrors(req, res)) return 50 if (areValidationErrors(req, res)) return
50 51
51 const plugin = res.locals.registeredPlugin 52 const plugin = res.locals.registeredPlugin
52 if (!plugin.registerHelpersStore) return res.sendStatus(404) 53 if (!plugin.registerHelpersStore) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
53 54
54 const externalAuth = plugin.registerHelpersStore.getExternalAuths().find(a => a.authName === req.params.authName) 55 const externalAuth = plugin.registerHelpersStore.getExternalAuths().find(a => a.authName === req.params.authName)
55 if (!externalAuth) return res.sendStatus(404) 56 if (!externalAuth) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
56 57
57 res.locals.externalAuth = externalAuth 58 res.locals.externalAuth = externalAuth
58 59
@@ -106,7 +107,7 @@ const installOrUpdatePluginValidator = [
106 107
107 const body: InstallOrUpdatePlugin = req.body 108 const body: InstallOrUpdatePlugin = req.body
108 if (!body.path && !body.npmName) { 109 if (!body.path && !body.npmName) {
109 return res.status(400) 110 return res.status(HttpStatusCode.BAD_REQUEST_400)
110 .json({ error: 'Should have either a npmName or a path' }) 111 .json({ error: 'Should have either a npmName or a path' })
111 .end() 112 .end()
112 } 113 }
@@ -137,9 +138,9 @@ const existingPluginValidator = [
137 138
138 const plugin = await PluginModel.loadByNpmName(req.params.npmName) 139 const plugin = await PluginModel.loadByNpmName(req.params.npmName)
139 if (!plugin) { 140 if (!plugin) {
140 return res.status(404) 141 return res.status(HttpStatusCode.NOT_FOUND_404)
141 .json({ error: 'Plugin not found' }) 142 .json({ error: 'Plugin not found' })
142 .end() 143 .end()
143 } 144 }
144 145
145 res.locals.plugin = plugin 146 res.locals.plugin = plugin
@@ -178,9 +179,9 @@ const listAvailablePluginsValidator = [
178 if (areValidationErrors(req, res)) return 179 if (areValidationErrors(req, res)) return
179 180
180 if (CONFIG.PLUGINS.INDEX.ENABLED === false) { 181 if (CONFIG.PLUGINS.INDEX.ENABLED === false) {
181 return res.status(400) 182 return res.status(HttpStatusCode.BAD_REQUEST_400)
182 .json({ error: 'Plugin index is not enabled' }) 183 .json({ error: 'Plugin index is not enabled' })
183 .end() 184 .end()
184 } 185 }
185 186
186 return next() 187 return next()