From c5911fd347c76e8bdc05ea9f3ee9efed4a58c236 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 29 Dec 2017 19:10:13 +0100 Subject: Begin to add avatar to actors --- server/helpers/custom-validators/users.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index 159c2a700..6ed60c1c4 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts @@ -1,7 +1,7 @@ import * as validator from 'validator' import 'express-validator' -import { exists } from './misc' +import { exists, isArray } from './misc' import { CONSTRAINTS_FIELDS } from '../../initializers' import { UserRole } from '../../../shared' @@ -37,6 +37,22 @@ function isUserRoleValid (value: any) { return exists(value) && validator.isInt('' + value) && UserRole[value] !== undefined } +function isAvatarFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) { + // Should have files + if (!files) return false + if (isArray(files)) return false + + // Should have videofile file + const avatarfile = files['avatarfile'] + if (!avatarfile || avatarfile.length === 0) return false + + // The file should exist + const file = avatarfile[0] + if (!file || !file.originalname) return false + + return new RegExp('^image/(png|jpeg)$', 'i').test(file.mimetype) +} + // --------------------------------------------------------------------------- export { @@ -45,5 +61,6 @@ export { isUserVideoQuotaValid, isUserUsernameValid, isUserDisplayNSFWValid, - isUserAutoPlayVideoValid + isUserAutoPlayVideoValid, + isAvatarFile } -- cgit v1.2.3