aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/validators/plugins.ts89
-rw-r--r--server/middlewares/validators/sort.ts5
2 files changed, 89 insertions, 5 deletions
diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.ts
index fcb461624..265ac7c17 100644
--- a/server/middlewares/validators/plugins.ts
+++ b/server/middlewares/validators/plugins.ts
@@ -1,10 +1,11 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param } from 'express-validator/check' 2import { param, query, body } from 'express-validator/check'
3import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils' 4import { areValidationErrors } from './utils'
5import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' 5import { isPluginNameValid, isPluginTypeValid, isPluginVersionValid, isNpmPluginNameValid } from '../../helpers/custom-validators/plugins'
6import { PluginManager } from '../../lib/plugins/plugin-manager' 6import { PluginManager } from '../../lib/plugins/plugin-manager'
7import { isSafePath } from '../../helpers/custom-validators/misc' 7import { isBooleanValid, isSafePath } from '../../helpers/custom-validators/misc'
8import { PluginModel } from '../../models/server/plugin'
8 9
9const servePluginStaticDirectoryValidator = [ 10const servePluginStaticDirectoryValidator = [
10 param('pluginName').custom(isPluginNameValid).withMessage('Should have a valid plugin name'), 11 param('pluginName').custom(isPluginNameValid).withMessage('Should have a valid plugin name'),
@@ -28,8 +29,88 @@ const servePluginStaticDirectoryValidator = [
28 } 29 }
29] 30]
30 31
32const listPluginsValidator = [
33 query('type')
34 .optional()
35 .custom(isPluginTypeValid).withMessage('Should have a valid plugin type'),
36 query('uninstalled')
37 .optional()
38 .toBoolean()
39 .custom(isBooleanValid).withMessage('Should have a valid uninstalled attribute'),
40
41 (req: express.Request, res: express.Response, next: express.NextFunction) => {
42 logger.debug('Checking listPluginsValidator parameters', { parameters: req.query })
43
44 if (areValidationErrors(req, res)) return
45
46 return next()
47 }
48]
49
50const installPluginValidator = [
51 body('npmName').custom(isNpmPluginNameValid).withMessage('Should have a valid npm name'),
52
53 (req: express.Request, res: express.Response, next: express.NextFunction) => {
54 logger.debug('Checking installPluginValidator parameters', { parameters: req.body })
55
56 if (areValidationErrors(req, res)) return
57
58 return next()
59 }
60]
61
62const uninstallPluginValidator = [
63 body('npmName').custom(isNpmPluginNameValid).withMessage('Should have a valid npm name'),
64
65 (req: express.Request, res: express.Response, next: express.NextFunction) => {
66 logger.debug('Checking managePluginValidator parameters', { parameters: req.body })
67
68 if (areValidationErrors(req, res)) return
69
70 return next()
71 }
72]
73
74const enabledPluginValidator = [
75 body('name').custom(isPluginNameValid).withMessage('Should have a valid plugin name'),
76
77 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
78 logger.debug('Checking enabledPluginValidator parameters', { parameters: req.body })
79
80 if (areValidationErrors(req, res)) return
81
82 const plugin = await PluginModel.load(req.body.name)
83 if (!plugin) {
84 return res.status(404)
85 .json({ error: 'Plugin not found' })
86 .end()
87 }
88
89 res.locals.plugin = plugin
90
91 return next()
92 }
93]
94
95const updatePluginSettingsValidator = [
96 body('settings').exists().withMessage('Should have settings'),
97
98 (req: express.Request, res: express.Response, next: express.NextFunction) => {
99 logger.debug('Checking enabledPluginValidator parameters', { parameters: req.body })
100
101 if (areValidationErrors(req, res)) return
102
103 return next()
104 }
105]
106
31// --------------------------------------------------------------------------- 107// ---------------------------------------------------------------------------
32 108
33export { 109export {
34 servePluginStaticDirectoryValidator 110 servePluginStaticDirectoryValidator,
111 updatePluginSettingsValidator,
112 uninstallPluginValidator,
113 enabledPluginValidator,
114 installPluginValidator,
115 listPluginsValidator
35} 116}
diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts
index b497798d1..102db85cb 100644
--- a/server/middlewares/validators/sort.ts
+++ b/server/middlewares/validators/sort.ts
@@ -21,6 +21,7 @@ const SORTABLE_ACCOUNTS_BLOCKLIST_COLUMNS = createSortableColumns(SORTABLE_COLUM
21const SORTABLE_SERVERS_BLOCKLIST_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.SERVERS_BLOCKLIST) 21const SORTABLE_SERVERS_BLOCKLIST_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.SERVERS_BLOCKLIST)
22const SORTABLE_USER_NOTIFICATIONS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USER_NOTIFICATIONS) 22const SORTABLE_USER_NOTIFICATIONS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USER_NOTIFICATIONS)
23const SORTABLE_VIDEO_PLAYLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_PLAYLISTS) 23const SORTABLE_VIDEO_PLAYLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_PLAYLISTS)
24const SORTABLE_PLUGINS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.PLUGINS)
24 25
25const usersSortValidator = checkSort(SORTABLE_USERS_COLUMNS) 26const usersSortValidator = checkSort(SORTABLE_USERS_COLUMNS)
26const accountsSortValidator = checkSort(SORTABLE_ACCOUNTS_COLUMNS) 27const accountsSortValidator = checkSort(SORTABLE_ACCOUNTS_COLUMNS)
@@ -41,6 +42,7 @@ const accountsBlocklistSortValidator = checkSort(SORTABLE_ACCOUNTS_BLOCKLIST_COL
41const serversBlocklistSortValidator = checkSort(SORTABLE_SERVERS_BLOCKLIST_COLUMNS) 42const serversBlocklistSortValidator = checkSort(SORTABLE_SERVERS_BLOCKLIST_COLUMNS)
42const userNotificationsSortValidator = checkSort(SORTABLE_USER_NOTIFICATIONS_COLUMNS) 43const userNotificationsSortValidator = checkSort(SORTABLE_USER_NOTIFICATIONS_COLUMNS)
43const videoPlaylistsSortValidator = checkSort(SORTABLE_VIDEO_PLAYLISTS_COLUMNS) 44const videoPlaylistsSortValidator = checkSort(SORTABLE_VIDEO_PLAYLISTS_COLUMNS)
45const pluginsSortValidator = checkSort(SORTABLE_PLUGINS_COLUMNS)
44 46
45// --------------------------------------------------------------------------- 47// ---------------------------------------------------------------------------
46 48
@@ -63,5 +65,6 @@ export {
63 accountsBlocklistSortValidator, 65 accountsBlocklistSortValidator,
64 serversBlocklistSortValidator, 66 serversBlocklistSortValidator,
65 userNotificationsSortValidator, 67 userNotificationsSortValidator,
66 videoPlaylistsSortValidator 68 videoPlaylistsSortValidator,
69 pluginsSortValidator
67} 70}