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/helpers/custom-validators/actor-images.ts | 17 +++++++++++++++++ server/helpers/custom-validators/users.ts | 13 ++----------- 2 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 server/helpers/custom-validators/actor-images.ts (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/actor-images.ts b/server/helpers/custom-validators/actor-images.ts new file mode 100644 index 000000000..4fb0b7c70 --- /dev/null +++ b/server/helpers/custom-validators/actor-images.ts @@ -0,0 +1,17 @@ + +import { CONSTRAINTS_FIELDS } from '../../initializers/constants' +import { isFileValid } from './misc' + +const imageMimeTypes = CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME + .map(v => v.replace('.', '')) + .join('|') +const imageMimeTypesRegex = `image/(${imageMimeTypes})` +function isActorImageFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], fieldname: string) { + return isFileValid(files, imageMimeTypesRegex, fieldname, CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max) +} + +// --------------------------------------------------------------------------- + +export { + isActorImageFile +} diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index 85f3634c8..5b21c3529 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts @@ -3,7 +3,7 @@ import validator from 'validator' import { UserRole } from '../../../shared' import { isEmailEnabled } from '../../initializers/config' import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants' -import { exists, isArray, isBooleanValid, isFileValid } from './misc' +import { exists, isArray, isBooleanValid } from './misc' const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS @@ -97,14 +97,6 @@ function isUserRoleValid (value: any) { return exists(value) && validator.isInt('' + value) && UserRole[value] !== undefined } -const avatarMimeTypes = CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME - .map(v => v.replace('.', '')) - .join('|') -const avatarMimeTypesRegex = `image/(${avatarMimeTypes})` -function isAvatarFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) { - return isFileValid(files, avatarMimeTypesRegex, 'avatarfile', CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max) -} - // --------------------------------------------------------------------------- export { @@ -128,6 +120,5 @@ export { isUserDisplayNameValid, isUserDescriptionValid, isNoInstanceConfigWarningModal, - isNoWelcomeModal, - isAvatarFile + isNoWelcomeModal } -- cgit v1.2.3