diff options
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/plugins.ts | 89 | ||||
-rw-r--r-- | server/middlewares/validators/sort.ts | 5 |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param } from 'express-validator/check' | 2 | import { param, query, body } from 'express-validator/check' |
3 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
4 | import { areValidationErrors } from './utils' | 4 | import { areValidationErrors } from './utils' |
5 | import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' | 5 | import { isPluginNameValid, isPluginTypeValid, isPluginVersionValid, isNpmPluginNameValid } from '../../helpers/custom-validators/plugins' |
6 | import { PluginManager } from '../../lib/plugins/plugin-manager' | 6 | import { PluginManager } from '../../lib/plugins/plugin-manager' |
7 | import { isSafePath } from '../../helpers/custom-validators/misc' | 7 | import { isBooleanValid, isSafePath } from '../../helpers/custom-validators/misc' |
8 | import { PluginModel } from '../../models/server/plugin' | ||
8 | 9 | ||
9 | const servePluginStaticDirectoryValidator = [ | 10 | const 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 | ||
32 | const 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 | |||
50 | const 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 | |||
62 | const 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 | |||
74 | const 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 | |||
95 | const 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 | ||
33 | export { | 109 | export { |
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 | |||
21 | const SORTABLE_SERVERS_BLOCKLIST_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.SERVERS_BLOCKLIST) | 21 | const SORTABLE_SERVERS_BLOCKLIST_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.SERVERS_BLOCKLIST) |
22 | const SORTABLE_USER_NOTIFICATIONS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USER_NOTIFICATIONS) | 22 | const SORTABLE_USER_NOTIFICATIONS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USER_NOTIFICATIONS) |
23 | const SORTABLE_VIDEO_PLAYLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_PLAYLISTS) | 23 | const SORTABLE_VIDEO_PLAYLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_PLAYLISTS) |
24 | const SORTABLE_PLUGINS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.PLUGINS) | ||
24 | 25 | ||
25 | const usersSortValidator = checkSort(SORTABLE_USERS_COLUMNS) | 26 | const usersSortValidator = checkSort(SORTABLE_USERS_COLUMNS) |
26 | const accountsSortValidator = checkSort(SORTABLE_ACCOUNTS_COLUMNS) | 27 | const accountsSortValidator = checkSort(SORTABLE_ACCOUNTS_COLUMNS) |
@@ -41,6 +42,7 @@ const accountsBlocklistSortValidator = checkSort(SORTABLE_ACCOUNTS_BLOCKLIST_COL | |||
41 | const serversBlocklistSortValidator = checkSort(SORTABLE_SERVERS_BLOCKLIST_COLUMNS) | 42 | const serversBlocklistSortValidator = checkSort(SORTABLE_SERVERS_BLOCKLIST_COLUMNS) |
42 | const userNotificationsSortValidator = checkSort(SORTABLE_USER_NOTIFICATIONS_COLUMNS) | 43 | const userNotificationsSortValidator = checkSort(SORTABLE_USER_NOTIFICATIONS_COLUMNS) |
43 | const videoPlaylistsSortValidator = checkSort(SORTABLE_VIDEO_PLAYLISTS_COLUMNS) | 44 | const videoPlaylistsSortValidator = checkSort(SORTABLE_VIDEO_PLAYLISTS_COLUMNS) |
45 | const 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 | } |