diff options
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/users.ts | 21 |
1 files changed, 19 insertions, 2 deletions
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 @@ | |||
1 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | 3 | ||
4 | import { exists } from './misc' | 4 | import { exists, isArray } from './misc' |
5 | import { CONSTRAINTS_FIELDS } from '../../initializers' | 5 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
6 | import { UserRole } from '../../../shared' | 6 | import { UserRole } from '../../../shared' |
7 | 7 | ||
@@ -37,6 +37,22 @@ function isUserRoleValid (value: any) { | |||
37 | return exists(value) && validator.isInt('' + value) && UserRole[value] !== undefined | 37 | return exists(value) && validator.isInt('' + value) && UserRole[value] !== undefined |
38 | } | 38 | } |
39 | 39 | ||
40 | function isAvatarFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) { | ||
41 | // Should have files | ||
42 | if (!files) return false | ||
43 | if (isArray(files)) return false | ||
44 | |||
45 | // Should have videofile file | ||
46 | const avatarfile = files['avatarfile'] | ||
47 | if (!avatarfile || avatarfile.length === 0) return false | ||
48 | |||
49 | // The file should exist | ||
50 | const file = avatarfile[0] | ||
51 | if (!file || !file.originalname) return false | ||
52 | |||
53 | return new RegExp('^image/(png|jpeg)$', 'i').test(file.mimetype) | ||
54 | } | ||
55 | |||
40 | // --------------------------------------------------------------------------- | 56 | // --------------------------------------------------------------------------- |
41 | 57 | ||
42 | export { | 58 | export { |
@@ -45,5 +61,6 @@ export { | |||
45 | isUserVideoQuotaValid, | 61 | isUserVideoQuotaValid, |
46 | isUserUsernameValid, | 62 | isUserUsernameValid, |
47 | isUserDisplayNSFWValid, | 63 | isUserDisplayNSFWValid, |
48 | isUserAutoPlayVideoValid | 64 | isUserAutoPlayVideoValid, |
65 | isAvatarFile | ||
49 | } | 66 | } |