aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/users.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-02-13 18:17:05 +0100
committerChocobozzz <me@florianbigard.com>2018-02-14 16:03:09 +0100
commitac81d1a06d57b9ae86663831e7f5edcef57b0fa4 (patch)
treeda31775c9533d3e270f68f921e146f086bf7c0b8 /server/helpers/custom-validators/users.ts
parente883399fa6caa56bb8519c9a2e22d88001f26661 (diff)
downloadPeerTube-ac81d1a06d57b9ae86663831e7f5edcef57b0fa4.tar.gz
PeerTube-ac81d1a06d57b9ae86663831e7f5edcef57b0fa4.tar.zst
PeerTube-ac81d1a06d57b9ae86663831e7f5edcef57b0fa4.zip
Add ability to set video thumbnail/preview
Diffstat (limited to 'server/helpers/custom-validators/users.ts')
-rw-r--r--server/helpers/custom-validators/users.ts26
1 files changed, 9 insertions, 17 deletions
diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts
index 6ed60c1c4..e805313f8 100644
--- a/server/helpers/custom-validators/users.ts
+++ b/server/helpers/custom-validators/users.ts
@@ -1,9 +1,9 @@
1import * as validator from 'validator'
2import 'express-validator' 1import 'express-validator'
3 2import * as validator from 'validator'
4import { exists, isArray } from './misc'
5import { CONSTRAINTS_FIELDS } from '../../initializers'
6import { UserRole } from '../../../shared' 3import { UserRole } from '../../../shared'
4import { CONSTRAINTS_FIELDS } from '../../initializers'
5
6import { exists, isFileValid } from './misc'
7 7
8const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS 8const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS
9 9
@@ -37,20 +37,12 @@ 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
40const avatarMimeTypes = CONSTRAINTS_FIELDS.ACTORS.AVATAR.EXTNAME
41 .map(v => v.replace('.', ''))
42 .join('|')
43const avatarMimeTypesRegex = `image/(${avatarMimeTypes})`
40function isAvatarFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) { 44function isAvatarFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) {
41 // Should have files 45 return isFileValid(files, avatarMimeTypesRegex, 'avatarfile')
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} 46}
55 47
56// --------------------------------------------------------------------------- 48// ---------------------------------------------------------------------------