diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-05-15 22:22:03 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-05-20 09:57:40 +0200 |
commit | 65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch) | |
tree | 4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/helpers/custom-validators/videos.js | |
parent | d5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff) | |
download | PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip |
First typescript iteration
Diffstat (limited to 'server/helpers/custom-validators/videos.js')
-rw-r--r-- | server/helpers/custom-validators/videos.js | 148 |
1 files changed, 0 insertions, 148 deletions
diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js deleted file mode 100644 index 196731e04..000000000 --- a/server/helpers/custom-validators/videos.js +++ /dev/null | |||
@@ -1,148 +0,0 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const validator = require('express-validator').validator | ||
4 | const values = require('lodash/values') | ||
5 | |||
6 | const constants = require('../../initializers/constants') | ||
7 | const usersValidators = require('./users') | ||
8 | const miscValidators = require('./misc') | ||
9 | const VIDEOS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEOS | ||
10 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEO_ABUSES | ||
11 | const VIDEO_EVENTS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEO_EVENTS | ||
12 | |||
13 | const videosValidators = { | ||
14 | isVideoAuthorValid, | ||
15 | isVideoDateValid, | ||
16 | isVideoCategoryValid, | ||
17 | isVideoLicenceValid, | ||
18 | isVideoLanguageValid, | ||
19 | isVideoNSFWValid, | ||
20 | isVideoDescriptionValid, | ||
21 | isVideoDurationValid, | ||
22 | isVideoInfoHashValid, | ||
23 | isVideoNameValid, | ||
24 | isVideoTagsValid, | ||
25 | isVideoThumbnailValid, | ||
26 | isVideoThumbnailDataValid, | ||
27 | isVideoExtnameValid, | ||
28 | isVideoRemoteIdValid, | ||
29 | isVideoAbuseReasonValid, | ||
30 | isVideoAbuseReporterUsernameValid, | ||
31 | isVideoFile, | ||
32 | isVideoViewsValid, | ||
33 | isVideoLikesValid, | ||
34 | isVideoRatingTypeValid, | ||
35 | isVideoDislikesValid, | ||
36 | isVideoEventCountValid | ||
37 | } | ||
38 | |||
39 | function isVideoAuthorValid (value) { | ||
40 | return usersValidators.isUserUsernameValid(value) | ||
41 | } | ||
42 | |||
43 | function isVideoDateValid (value) { | ||
44 | return validator.isDate(value) | ||
45 | } | ||
46 | |||
47 | function isVideoCategoryValid (value) { | ||
48 | return constants.VIDEO_CATEGORIES[value] !== undefined | ||
49 | } | ||
50 | |||
51 | function isVideoLicenceValid (value) { | ||
52 | return constants.VIDEO_LICENCES[value] !== undefined | ||
53 | } | ||
54 | |||
55 | function isVideoLanguageValid (value) { | ||
56 | return value === null || constants.VIDEO_LANGUAGES[value] !== undefined | ||
57 | } | ||
58 | |||
59 | function isVideoNSFWValid (value) { | ||
60 | return validator.isBoolean(value) | ||
61 | } | ||
62 | |||
63 | function isVideoDescriptionValid (value) { | ||
64 | return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION) | ||
65 | } | ||
66 | |||
67 | function isVideoDurationValid (value) { | ||
68 | return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION) | ||
69 | } | ||
70 | |||
71 | function isVideoExtnameValid (value) { | ||
72 | return VIDEOS_CONSTRAINTS_FIELDS.EXTNAME.indexOf(value) !== -1 | ||
73 | } | ||
74 | |||
75 | function isVideoInfoHashValid (value) { | ||
76 | return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH) | ||
77 | } | ||
78 | |||
79 | function isVideoNameValid (value) { | ||
80 | return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME) | ||
81 | } | ||
82 | |||
83 | function isVideoTagsValid (tags) { | ||
84 | return miscValidators.isArray(tags) && | ||
85 | validator.isInt(tags.length, VIDEOS_CONSTRAINTS_FIELDS.TAGS) && | ||
86 | tags.every(function (tag) { | ||
87 | return validator.isLength(tag, VIDEOS_CONSTRAINTS_FIELDS.TAG) | ||
88 | }) | ||
89 | } | ||
90 | |||
91 | function isVideoThumbnailValid (value) { | ||
92 | return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL) | ||
93 | } | ||
94 | |||
95 | function isVideoThumbnailDataValid (value) { | ||
96 | return validator.isByteLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL_DATA) | ||
97 | } | ||
98 | |||
99 | function isVideoRemoteIdValid (value) { | ||
100 | return validator.isUUID(value, 4) | ||
101 | } | ||
102 | |||
103 | function isVideoAbuseReasonValid (value) { | ||
104 | return validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON) | ||
105 | } | ||
106 | |||
107 | function isVideoAbuseReporterUsernameValid (value) { | ||
108 | return usersValidators.isUserUsernameValid(value) | ||
109 | } | ||
110 | |||
111 | function isVideoViewsValid (value) { | ||
112 | return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.VIEWS) | ||
113 | } | ||
114 | |||
115 | function isVideoLikesValid (value) { | ||
116 | return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.LIKES) | ||
117 | } | ||
118 | |||
119 | function isVideoDislikesValid (value) { | ||
120 | return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DISLIKES) | ||
121 | } | ||
122 | |||
123 | function isVideoEventCountValid (value) { | ||
124 | return validator.isInt(value + '', VIDEO_EVENTS_CONSTRAINTS_FIELDS.COUNT) | ||
125 | } | ||
126 | |||
127 | function isVideoRatingTypeValid (value) { | ||
128 | return values(constants.VIDEO_RATE_TYPES).indexOf(value) !== -1 | ||
129 | } | ||
130 | |||
131 | function isVideoFile (value, files) { | ||
132 | // Should have files | ||
133 | if (!files) return false | ||
134 | |||
135 | // Should have videofile file | ||
136 | const videofile = files.videofile | ||
137 | if (!videofile || videofile.length === 0) return false | ||
138 | |||
139 | // The file should exist | ||
140 | const file = videofile[0] | ||
141 | if (!file || !file.originalname) return false | ||
142 | |||
143 | return new RegExp('^video/(webm|mp4|ogg)$', 'i').test(file.mimetype) | ||
144 | } | ||
145 | |||
146 | // --------------------------------------------------------------------------- | ||
147 | |||
148 | module.exports = videosValidators | ||