diff options
author | Chocobozzz <me@florianbigard.com> | 2018-02-13 18:17:05 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-02-14 16:03:09 +0100 |
commit | ac81d1a06d57b9ae86663831e7f5edcef57b0fa4 (patch) | |
tree | da31775c9533d3e270f68f921e146f086bf7c0b8 /server/helpers/custom-validators/misc.ts | |
parent | e883399fa6caa56bb8519c9a2e22d88001f26661 (diff) | |
download | PeerTube-ac81d1a06d57b9ae86663831e7f5edcef57b0fa4.tar.gz PeerTube-ac81d1a06d57b9ae86663831e7f5edcef57b0fa4.tar.zst PeerTube-ac81d1a06d57b9ae86663831e7f5edcef57b0fa4.zip |
Add ability to set video thumbnail/preview
Diffstat (limited to 'server/helpers/custom-validators/misc.ts')
-rw-r--r-- | server/helpers/custom-validators/misc.ts | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts index 3903884ea..8a270b777 100644 --- a/server/helpers/custom-validators/misc.ts +++ b/server/helpers/custom-validators/misc.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import 'multer' | ||
1 | import * as validator from 'validator' | 2 | import * as validator from 'validator' |
2 | 3 | ||
3 | function exists (value: any) { | 4 | function exists (value: any) { |
@@ -28,6 +29,29 @@ function isBooleanValid (value: string) { | |||
28 | return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value)) | 29 | return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value)) |
29 | } | 30 | } |
30 | 31 | ||
32 | function isFileValid ( | ||
33 | files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], | ||
34 | mimeTypeRegex: string, | ||
35 | field: string, | ||
36 | optional = false | ||
37 | ) { | ||
38 | // Should have files | ||
39 | if (!files) return optional | ||
40 | if (isArray(files)) return optional | ||
41 | |||
42 | // Should have a file | ||
43 | const fileArray = files[ field ] | ||
44 | if (!fileArray || fileArray.length === 0) { | ||
45 | return optional | ||
46 | } | ||
47 | |||
48 | // The file should exist | ||
49 | const file = fileArray[ 0 ] | ||
50 | if (!file || !file.originalname) return false | ||
51 | |||
52 | return new RegExp(`^${mimeTypeRegex}$`, 'i').test(file.mimetype) | ||
53 | } | ||
54 | |||
31 | // --------------------------------------------------------------------------- | 55 | // --------------------------------------------------------------------------- |
32 | 56 | ||
33 | export { | 57 | export { |
@@ -37,5 +61,6 @@ export { | |||
37 | isUUIDValid, | 61 | isUUIDValid, |
38 | isIdOrUUIDValid, | 62 | isIdOrUUIDValid, |
39 | isDateValid, | 63 | isDateValid, |
40 | isBooleanValid | 64 | isBooleanValid, |
65 | isFileValid | ||
41 | } | 66 | } |