From 7cd4d2ba10106c10602c86f74f55743ded588896 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 9 Jul 2019 11:45:19 +0200 Subject: WIP plugins: add theme support --- server/middlewares/validators/config.ts | 5 ++++- server/middlewares/validators/plugins.ts | 2 +- server/middlewares/validators/users.ts | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts index d015fa6fe..31b131914 100644 --- a/server/middlewares/validators/config.ts +++ b/server/middlewares/validators/config.ts @@ -1,10 +1,11 @@ import * as express from 'express' import { body } from 'express-validator/check' -import { isUserNSFWPolicyValid, isUserVideoQuotaValid, isUserVideoQuotaDailyValid } from '../../helpers/custom-validators/users' +import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' import { logger } from '../../helpers/logger' import { CustomConfig } from '../../../shared/models/server/custom-config.model' import { Emailer } from '../../lib/emailer' import { areValidationErrors } from './utils' +import { isThemeValid } from '../../helpers/custom-validators/plugins' const customConfigUpdateValidator = [ body('instance.name').exists().withMessage('Should have a valid instance name'), @@ -47,6 +48,8 @@ const customConfigUpdateValidator = [ body('followers.instance.enabled').isBoolean().withMessage('Should have a valid followers of instance boolean'), body('followers.instance.manualApproval').isBoolean().withMessage('Should have a valid manual approval boolean'), + body('theme.default').custom(isThemeValid).withMessage('Should have a valid theme'), + async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body }) diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.ts index 672299ee1..fcb461624 100644 --- a/server/middlewares/validators/plugins.ts +++ b/server/middlewares/validators/plugins.ts @@ -16,7 +16,7 @@ const servePluginStaticDirectoryValidator = [ if (areValidationErrors(req, res)) return - const plugin = PluginManager.Instance.getRegisteredPlugin(req.params.pluginName) + const plugin = PluginManager.Instance.getRegisteredPluginOrTheme(req.params.pluginName) if (!plugin || plugin.version !== req.params.pluginVersion) { return res.sendStatus(404) diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index 947ed36c3..df7f77b84 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts @@ -28,6 +28,7 @@ import { ActorModel } from '../../models/activitypub/actor' import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' import { isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels' import { UserRegister } from '../../../shared/models/users/user-register.model' +import { isThemeValid } from '../../helpers/custom-validators/plugins' const usersAddValidator = [ body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), @@ -204,6 +205,9 @@ const usersUpdateMeValidator = [ body('videosHistoryEnabled') .optional() .custom(isUserVideosHistoryEnabledValid).withMessage('Should have a valid videos history enabled attribute'), + body('theme') + .optional() + .custom(isThemeValid).withMessage('Should have a valid theme'), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking usersUpdateMe parameters', { parameters: omit(req.body, 'password') }) -- cgit v1.2.3