From 213e30ef90806369529684ac9c247d73b8dc7928 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Apr 2021 10:36:13 +0200 Subject: Add banner tests --- server/middlewares/validators/actor-image.ts | 30 ++++++++++++++++++++++++++++ server/middlewares/validators/avatar.ts | 30 ---------------------------- server/middlewares/validators/index.ts | 1 + 3 files changed, 31 insertions(+), 30 deletions(-) create mode 100644 server/middlewares/validators/actor-image.ts delete mode 100644 server/middlewares/validators/avatar.ts (limited to 'server/middlewares/validators') diff --git a/server/middlewares/validators/actor-image.ts b/server/middlewares/validators/actor-image.ts new file mode 100644 index 000000000..961d7a7e5 --- /dev/null +++ b/server/middlewares/validators/actor-image.ts @@ -0,0 +1,30 @@ +import * as express from 'express' +import { body } from 'express-validator' +import { isActorImageFile } from '@server/helpers/custom-validators/actor-images' +import { cleanUpReqFiles } from '../../helpers/express-utils' +import { logger } from '../../helpers/logger' +import { CONSTRAINTS_FIELDS } from '../../initializers/constants' +import { areValidationErrors } from './utils' + +const updateActorImageValidatorFactory = (fieldname: string) => ([ + body(fieldname).custom((value, { req }) => isActorImageFile(req.files, fieldname)).withMessage( + 'This file is not supported or too large. Please, make sure it is of the following type : ' + + CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME.join(', ') + ), + + (req: express.Request, res: express.Response, next: express.NextFunction) => { + logger.debug('Checking updateActorImageValidator parameters', { files: req.files }) + + if (areValidationErrors(req, res)) return cleanUpReqFiles(req) + + return next() + } +]) + +const updateAvatarValidator = updateActorImageValidatorFactory('avatarfile') +const updateBannerValidator = updateActorImageValidatorFactory('bannerfile') + +export { + updateAvatarValidator, + updateBannerValidator +} diff --git a/server/middlewares/validators/avatar.ts b/server/middlewares/validators/avatar.ts deleted file mode 100644 index f7eb367bd..000000000 --- a/server/middlewares/validators/avatar.ts +++ /dev/null @@ -1,30 +0,0 @@ -import * as express from 'express' -import { body } from 'express-validator' -import { isAvatarFile } from '../../helpers/custom-validators/users' -import { areValidationErrors } from './utils' -import { CONSTRAINTS_FIELDS } from '../../initializers/constants' -import { logger } from '../../helpers/logger' -import { cleanUpReqFiles } from '../../helpers/express-utils' - -const updateActorImageValidatorFactory = (fieldname: string) => ([ - body(fieldname).custom((value, { req }) => isAvatarFile(req.files)).withMessage( - 'This file is not supported or too large. Please, make sure it is of the following type : ' + - CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME.join(', ') - ), - - (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking updateActorImageValidator parameters', { files: req.files }) - - if (areValidationErrors(req, res)) return cleanUpReqFiles(req) - - return next() - } -]) - -const updateAvatarValidator = updateActorImageValidatorFactory('avatarfile') -const updateBannerValidator = updateActorImageValidatorFactory('bannerfile') - -export { - updateAvatarValidator, - updateBannerValidator -} diff --git a/server/middlewares/validators/index.ts b/server/middlewares/validators/index.ts index 4086d77aa..24faeea3e 100644 --- a/server/middlewares/validators/index.ts +++ b/server/middlewares/validators/index.ts @@ -1,5 +1,6 @@ export * from './abuse' export * from './account' +export * from './actor-image' export * from './blocklist' export * from './oembed' export * from './activitypub' -- cgit v1.2.3